How to Debug a Drools Project
There are different ways to debug
a drools project.
In this tutorial we will learn the one which requires writing a Utility class to let you know which rules are being triggered or fired.
With this approach we can check what all rules are getting triggered in our drools project.
Here is our Utility Class : Helper.java
package com.sample;
import org.drools.spi.KnowledgeHelper;
public class Helper {
public static void help(final KnowledgeHelper drools, final String message) {
System.out.println(message);
System.out.println("\nrule triggered: " + drools.getRule().getName());
}
public static void helper(final KnowledgeHelper drools){
System.out.println("\nrule triggered: " + drools.getRule().getName());
}
}
The first method help
prints the rule triggered along with some extra info which you can pass as String via the drl file.
The second rule helper
prints whether the particular rule was triggered or not.