我使用eclipse进行optaplanner项目开发,我可以毫无问题地从eclipse执行我的代码。要将此项目作为可执行文件,我使用eclipse导出向导将其导出为jar文件。
然后我使用命令java -jar myOptaPlanner.jar
从终端运行我的jar,然后,我得到以下错误
WARN given scan urls are empty. set urls in the configuration
Exception in thread "main" java.lang.IllegalStateException: The scanAnnotatedClasses
(ScanAnnotatedClassesConfig()) did not find any classes with a PlanningSolution
annotation.
Maybe you forgot to annotate a class with a PlanningSolution annotation.
Maybe you're using special classloading mechanisms (OSGi, ...) and this is a bug.
If you can confirm that, report it to our issue tracker and workaround it by
defining the classes explicitly in the solver configuration.
at org.optaplanner.core.config.domain.ScanAnnotatedClassesConfig.loadSolutionClass(ScanAnnotatedClassesConfig.java:106)
at org.optaplanner.core.config.domain.ScanAnnotatedClassesConfig.buildSolutionDescriptor(ScanAnnotatedClassesConfig.java:86)
at org.optaplanner.core.config.solver.SolverConfig.buildSolutionDescriptor(SolverConfig.java:270)
at org.optaplanner.core.config.solver.SolverConfig.buildSolver(SolverConfig.java:216)
at org.optaplanner.core.impl.solver.AbstractSolverFactory.buildSolver(AbstractSolverFactory.java:57)
at org.roster.app.WorkerRosteringApp.main(WorkerRosteringApp.java:36)
这真的是一个错误,还是我输错了?
更新:我尝试使用maven-shade-plugin
导出jar,而且我也遇到了同样的错误。
由于
答案 0 :(得分:3)
scanAnnotatedClasses似乎不适用于jar文件。相反,请使用以下解决方法:
<solutionClass>path.to.your.SolutionClass</solutionClass>
<entityClass>path.to.your.EntityClassI</entityClass>
<entityClass>path.to.your.EntityClassII</entityClass>
并删除配置文件中的scanAnnotatedClasses
。
答案 1 :(得分:2)
如果您不想手动声明解决方案和实体类,包括包含解决方案和实体类的包也可以解决方法:
<scanAnnotatedClasses>
<packageInclude>your.package.here</packageInclude>
</scanAnnotatedClasses>
可以找到有关<packageInclude>
的文档here