[英]How to have the equivalent of main/resources in a non-Maven project?
I was trying to model my project based on this project at Github. 我试图在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 ). SOLVER_CONFIG
中提到的文件位于resources
目录中( 请参阅此处 )。
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 . 我知道
main/resources
对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?
我必须在哪里放置文件,我必须在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. Maven所做的只是将
src/main/resources
包/目录树合并到目标类路径中,并保持相同的包/文件夹布局。
如果手动构建,则需要将资源手动复制到类路径中,即,将XML文件复制到生成的类目录的根路径中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.