I was trying to model my project based on this project at 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();
}
The file mentioned in SOLVER_CONFIG
lies in the resources
directory ( see here ).
I tried to do the same thing .
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();
}
}
And there was fail.
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)
I understand that main/resources
mean something for Maven builds . But I am building my project manually.
Question: How do I implement the same thing (from resources) in my own project? Where must I place the file and what must I specify in the SOLVER_CONFIG?
The function itself is implemented as:
public XmlSolverConfigurer configure(String resource) {
return configure(getClass().getResourceAsStream(resource));
}
Put the resources on the classpath, for example, in the source directory.
All Maven does is merge the src/main/resources
package/directory tree into the target classpath, maintaining the same package/folder layout.
如果手动构建,则需要将资源手动复制到类路径中,即,将XML文件复制到生成的类目录的根路径中。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.