Optaplanner - 运行 可执行 jar 时出错,但在 eclipse 中工作正常

Optaplanner - Error when running executable jar but works fine from eclipse

我使用 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,这里我也遇到了同样的错误。

谢谢

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

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

并删除配置文件中的 scanAnnotatedClasses

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

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

可以找到关于 <packageInclude> 的文档 here