2016-12-11 126 views
0

我使用eclipse進行optaplanner項目開發,並且能夠從eclipse執行我的代碼而沒有任何問題。爲了使這個項目成爲可執行文件,我使用eclipse導出嚮導將其導出爲jar文件。Optaplanner - 運行可執行jar時出錯,但在eclipse中正常工作

然後我從運行使用命令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) 

這真的是一個錯誤還是我出口是錯誤的?

更新:我試圖導出使用maven-shade-plugin罐子,這裏也出現同樣的錯誤。

感謝

+0

在封面之下,OptaPlanner使用org.reflections掃描類路徑。我用罐子測試了這個沒有任何問題。你在使用OSGi,Jigsaw,JBoss模塊還是其他特殊的類加載環境? –

回答

2

scanAnnotatedClasses似乎並不在一個jar文件的工作。相反,使用以下解決方法:

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

並在您的配置文件中刪除scanAnnotatedClasses

+0

非常感謝您的幫助......現在正在開展工作。你覺得我不得不把它作爲一個bug發佈給他們嗎? – Selva

+0

是的,這是一個錯誤,請[在這裏報告](https://issues.jboss.org/projects/PLANNER)並提供一個乾淨的複製品 –

+0

或者更好的是,找出問題所在[通過調試此代碼](https://github.com/droolsjbpm/optaplanner/blob/master/optaplanner-core/src/main/java/org/optaplanner/core/config/domain/ScanAnnotatedClassesConfig.java#L86),如果你想貢獻。 –

0

如果不想手動聲明的解決方案和實體類,包括裝有溶液和實體類還包工作方式解決方法:

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

文檔關於<packageInclude>可以發現here

相關問題