I wrote a "minimal" App using OpenJDK 11.0.11 & Optaplanner 8.7.0. I'm building it with maven and run it as a jar.
So far so good, as this works fine with a easyScoreCalculatorClass, but as soon as I move to using Drools I cannot get passed the following error:
Exception in thread "main" java.lang.IllegalStateException: There is an error in a scoreDrl or scoreDrlFile.
at org.optaplanner.core.impl.score.director.ScoreDirectorFactoryFactory.buildDroolsScoreDirectorFactory(ScoreDirectorFactoryFactory.java:323)
at org.optaplanner.core.impl.score.director.ScoreDirectorFactoryFactory.decideMultipleScoreDirectorFactories(ScoreDirectorFactoryFactory.java:108)
at org.optaplanner.core.impl.score.director.ScoreDirectorFactoryFactory.buildScoreDirectorFactory(ScoreDirectorFactoryFactory.java:73)
at org.optaplanner.core.impl.solver.DefaultSolverFactory.buildScoreDirectorFactory(DefaultSolverFactory.java:116)
at org.optaplanner.core.impl.solver.DefaultSolverFactory.buildSolver(DefaultSolverFactory.java:83)
at ch.twohundredok.compute.App.main(App.java:56)
Caused by: java.lang.NullPointerException
at org.kie.internal.utils.KieHelper.<init>(KieHelper.java:46)
at org.optaplanner.core.impl.score.director.ScoreDirectorFactoryFactory.buildDroolsScoreDirectorFactory(ScoreDirectorFactoryFactory.java:290)
... 5 more
The exception occurs as soon as solverFactory.buildSolver()
is called.
This is the minimal drools file I'm trying to use:
package myapp;
dialect "java"
import myapp.domain.Employee;
import org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScoreHolder;
global HardSoftScoreHolder scoreHolder;
rule "firstRule"
when
Employee()
then
scoreHolder.addHardConstraintMatch(kcontext, -1);
end
The unfortunate fact is that Drools isn't very good at exceptions when things go wrong. I do not see anything obviously wrong in the code you provided, and the fact that the failure comes from KieHelper
is strange. That said, I do not have any information to go on, and would need access to your project to be able to find out more.
In the past, there have been several issues with people building executable JARs with Drools in Maven. See this question for one such problem, incl. the solution.
That said, if you're only just starting with your project, I suggest you use Constraint Streams instead. The programming model is very similar, but the code is plain Java, so you get all the IDE magic such as auto-completion, compiler checks etc.