![](/img/trans.png)
[英]How to add a local non-maven project as a dependency for a maven project?
[英]How to have the equivalent of main/resources in a non-Maven project?
我试图在Github上基于该项目对我的项目进行建模。
public class DroolsPlannerPoCApp {
....
private static final String SOLVER_CONFIG = "/ServiceDeliverySolverConfig.xml";
....
private Solver createSolver() {
XmlSolverConfigurer configurer = new XmlSolverConfigurer();
configurer.configure( SOLVER_CONFIG );
return configurer.buildSolver();
}
SOLVER_CONFIG
中提到的文件位于resources
目录中( 请参阅此处 )。
我试图做同样的事情 。
package in.co.technovia.sudoku;
import java.util.ArrayList;
....
public class App{
private static final String SOLVER_CONFIG = "/solver.xml";
public static void main(String[] args){
SudokuGenerator sg = new SudokuGenerator();
....
}
private static Solver createSolver(){
XmlSolverConfigurer configurer = new XmlSolverConfigurer();
configurer.configure(SOLVER_CONFIG);
return configurer.buildSolver();
}
}
失败了。
jesvin@Jesvin-Technovia:~/dev/drools/sudoku$ java in.co.technovia.sudoku.AppException in thread "main" java.lang.IllegalArgumentException: The solver configuration (/solver.xml) does not exist.
at org.drools.planner.config.XmlSolverConfigurer.configure(XmlSolverConfigurer.java:79)
at in.co.technovia.sudoku.App.createSolver(App.java:67)
at in.co.technovia.sudoku.App.main(App.java:43)
我知道main/resources
对Maven builds有意义 。 但是我正在手动构建项目。
问题:如何在自己的项目中实现同一件事(通过资源)? 我必须在哪里放置文件,我必须在SOLVER_CONFIG中指定什么?
该函数本身实现为:
public XmlSolverConfigurer configure(String resource) {
return configure(getClass().getResourceAsStream(resource));
}
将资源放在类路径上,例如,在源目录中。
Maven所做的只是将src/main/resources
包/目录树合并到目标类路径中,并保持相同的包/文件夹布局。
如果手动构建,则需要将资源手动复制到类路径中,即,将XML文件复制到生成的类目录的根路径中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.