Drools Debugging - Drools

How to debug a Drools project?

This chapter explains about different ways to debug a Drools project. Here, we will write a Utility class to let you know which rules are being triggered or fired.
This approach enables you to check what all rules are getting triggered in your Drools project. Here is our Utility Class


The first method help enables to print the rule triggered along with some additional information which can be pass as String via the DRL file.
The second rule helper prints whether the particular rule was triggered or not.
Here we have added one of the Utility methods in each DRL file. The other import function in the DRL file (Pune.drl) also added. In the then part of the rule, we have added the utility function call. The modified Pune.drl is given below. Changes are highlighted in blue.

Modified Pune.drl

You can also add the other utility function in the second DRL file (Nagpur.drl). Here is the modified code:

Modified Nagpur.drl

Run the program again and it should produce the following output:
Here both the utility functions are called and displayed that the particular rule was called or not. The In the above example, all the rules are being called, but in an enterprise application, this utility function can be really useful to debug and find out whether a particular rule was fired or not.

Using the Debug Perspective in Eclipse

Drools allow you to debug the rules during the execution of your Drools application. Here you can add breakpoints in the consequences of your rules, as there is a breakpoint is includes while implementing the rules when the execution is stopped temporarily. You can then inspect the variables known at that point as you do in a Java Application, and use the normal debugging options available in Eclipse.
You need to double-click at the line where you want to create a breakpoint . Here you can only create a breakpoint in the then part of a rule. If you want to remove a breakpoint just double-click on the breakpoint in the DRL editor.
You need to debug your application as a Drools application after applying the breakpoints. Drools breakpoints (breakpoints in DRL file) will only work if your application is being debugged as a Drools application. Here is how you need to do the same:
After you debug your application as a Drools application, you would see the control on the DRL file as shown in the following screenshot:
You can see the variables and the current values of the object at that debug point. The same control of F6 to move to the next line and F8 to jump to the next debug point are applicable here as well. In this way, you can debug your Drools application.
Note: The debug perspective in Drools application works only if the dialect is MVEL until Drools 5.x.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Drools Topics