1

我将 eclipse 用于我的 optaplanner 项目开发,并且我能够毫无问题地从 eclipse 执行我的代码。为了使这个项目成为可执行文件,我使用 eclipse 导出向导将它导出为 jar 文件。

然后我使用命令从终端运行我的 jar java -jar myOptaPlanner.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)

这真的是一个错误还是我导出错误?

更新:我尝试使用导出 jar maven-shade-plugin,在这里我也遇到了同样的错误。

谢谢

4

2 回答 2

4

scanAnnotatedClasses 似乎在 jar 文件中不起作用。相反,请使用以下解决方法:

<solutionClass>path.to.your.SolutionClass</solutionClass>
<entityClass>path.to.your.EntityClassI</entityClass>
<entityClass>path.to.your.EntityClassII</entityClass>

并删除scanAnnotatedClasses您的配置文件中的。

于 2016-12-12T15:14:21.060 回答
2

如果您不想手动声明解决方案和实体类,包括包含解决方案和实体类的包也可以作为解决方法:

<scanAnnotatedClasses>
    <packageInclude>your.package.here</packageInclude>
</scanAnnotatedClasses>

关于文档<packageInclude>可以在这里找到

于 2017-01-09T13:45:06.977 回答