Question

I have a Drools file within a Java program (in this case a variation of Optaplanner), which I am building on Netbeans 8. When I run the program I get an error message:

Exception in thread "main" java.lang.IllegalArgumentException: The scoreDrl (taskassignment/solver/taskAssignmentScoreRules.drl) does not exist as a classpath resource.
at org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig.buildKieBase(ScoreDirectorFactoryConfig.java:304)
at org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig.buildDroolsScoreDirectorFactory(ScoreDirectorFactoryConfig.java:279)
at org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig.buildScoreDirectorFactory(ScoreDirectorFactoryConfig.java:186)
at org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig.buildScoreDirectorFactory(ScoreDirectorFactoryConfig.java:174)
at org.optaplanner.core.config.solver.SolverConfig.buildSolver(SolverConfig.java:145)
at org.optaplanner.core.config.solver.XmlSolverFactory.buildSolver(XmlSolverFactory.java:101)
at taskassignment.app.TaskAssignmentHelloWorld.main(TaskAssignmentHelloWorld.java:32)

Having Googled the error mesage, it seems the does not exist as a classpath resource is thrown from Optaplanner when there is a mistake in the drools code.

My question is, with no further information on where the error(s) is/are in the drools file, what is a good way of debugging this piece of code? Are there any plugins that could help me narrow down where the problem is like Netbeans normally would with Java?

Here is my Drools code for good measure:

package taskassignment.solver;
dialect "java"

import org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScoreHolder;

import taskassignment.domain.TaskAssignment;
import taskassignment.domain.Task;
import taskassignment.domain.Dev;

global HardSoftScoreHolder scoreHolder;

// ############################################################################
// Hard constraints
// ############################################################################

rule "DevCanOnlyDoOneTask"
when
    $T1:Task
    $T2:Task
    $D:Dev
    (($T1.getAssignedDev()=$D)&&($T2.getAssignedDev()=$D)&&(($T2.getAllottedStartTime()<=$T1.getAllottedStartTime())&&($T1.getAllottedStartTime()<$T2.getAllottedStartTime()+$T2.getDuration()))||(($T1.getAllottedStartTime()<=$T2.getAllottedStartTime())&&($T2.getAllottedStartTime()<$T1.getAllottedStartTime()+$T1.getDuration()))

then
    scoreHolder.addHardConstraintMatch(kcontext,-1000);
end

// ############################################################################
// Soft constraints
// ############################################################################

rule "MaximiseEarliestFinishTime"
when
    $TA: TaskAssignment
    $EFT: $TA.getEFT()

then
    scoreHolder.addSoftConstraintMatch(kcontext,+$EFT);

Thanks guys

Était-ce utile?

La solution

When there is a mistake in the drools (DRL) code, it throws a different exception, coming from drools and stating on which line in the DRL the error message is.

The message

The scoreDrl (taskassignment/solver/taskAssignmentScoreRules.drl) does not exist as a classpath resource.

means that you've configured this in your solver config

<scoreDrl>taskassignment/solver/taskAssignmentScoreRules.drl</scoreDrl>

and that's not a valid classpath resource location.

In a typical project with a maven directory structure, classpath resources are located under src/main/resources.

Pitfall: In 6.0, OptaPlanner uses Class.getResource(String) to find it. In 6.1.0.Beta3+, OptaPlanner uses ClassLoader.getResource(String) to find it. This means that currently in 6.0 it needs to start with a / and in 6.1 it must not start with a /.

So if you have a resource file in your project sources like this (presuming you're using the maven directory structure):

PROJECT_DIR/src/main/resources/taskassignment/solver/taskAssignmentScoreRules.drl

In 6.0 you'd need to configure:

<scoreDrl>/taskassignment/solver/taskAssignmentScoreRules.drl</scoreDrl>

And in 6.1 you'd need to configure:

<scoreDrl>taskassignment/solver/taskAssignmentScoreRules.drl</scoreDrl>

Note: you probably want to follow java conventions and use reverse url namespace. So instead of taskassignment/solver/..., I 'd use com/mycompany/taskassignment/solver/....

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top