Search code examples
javadroolsexecutable-jaroptaplannerreflections

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


I use eclipse for my optaplanner project development and I am able to execute my code from eclipse without any problem. To make this project as an executable, I exported it as a jar file using eclipse export wizard.

Then I run my jar from terminal using the command java -jar myOptaPlanner.jar, then, I get below error

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)

Is this really a bug or am I exporting it wrong?

Update: I tried to export jar using maven-shade-plugin and here also I am getting the same error.

Thanks


Solution

  • scanAnnotatedClasses doesn't seem to work in a jar file. Instead, use following workaround:

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

    and delete the scanAnnotatedClasses in your config file.