gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 07:31:50 24 4
gpt4 key购买 nike

我将 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

关于java - Optaplanner - 运行可执行 jar 时出错,但在 eclipse 中运行正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41090401/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com