JBoss.orgCommunity Documentation

Drools Tools Reference Guide

Version: 5.0.0.CR1

April 2008


1. Introduction
1.1. What is Drools?
1.2. Drools Tools Key Features
1.3. Other relevant resources on the topic
2. Creating a New Drools Project
2.1. Creating a Sample Drools Project
2.2. Drools Project Structure Overview
2.3. Creating a New Rule
3. Debugging rules
3.1. Creating Breakpoints
3.2. Debugging
4. Editors
4.1. The Rule Editor
4.1.1. Content Assist
4.1.2. Code Folding
4.1.3. Synchronization with Outline View
4.1.4. The Rete Tree View

In this chapter we are going to show you how to setup an executable sample Drools project to start using rules immediately.

First, we suggest that you use Drools perspective which is aimed at work with Drools specific resources.

To create a new Drools project follow to File > New > Drools Project. This will open New Drools Project wizard like on the figure below.

On the first page type the project name and click Next.


Next you have a choice to add some default artifacts to it like sample rules, decision tables or ruleflows and Java classes for them. Let's select first two check boxes and press Next.


Next page asks you to specify a Drools runtime. If you have not yet set it up, you should do this now by clicking the Configure Workspace Settings link.


You should see the Preferences window where you can configure the workspace settings for Drools runtimes. To create a new runtime, press the Add button. The appeared dialog prompts you to enter a name for a new runtime and a path to the Drools runtime on your file system.

Note:

A Drools runtime is a collection of jars on your file system that represent one specific release of the Drools project jars. While creating a new runtime, you must either point to the release of your choice, or you can simply create a new runtime on your file system from the jars included in the Drools Eclipse plugin.


Let's simply create a new Drools 5 runtime from the jars embedded in the Drools Eclipse plugin. Thus, you should press Create a new Drools 5 runtime button and select the folder where you want this runtime to be created and hit OK.

You will see the newly created runtime show up in your list of Drools runtimes. Check it and press OK.


Now press Finish to complete the project creation.


This will setup a basic structure, classpath and sample rules and test case to get you started.

This chapter describes how to debug rules during the execution of your Drools application.

Drools breakpoints are only enabled if you debug your application as a Drools Application. To do this you should perform one of the actions:


  • Alternatively, you can also go to Debug As > Debug Configuration to open a new dialog for creating, managing and running debug configurations.

    Select the Drools Application item in the left tree and click the New launch configuration button (leftmost icon in the toolbar above the tree). This will create a new configuration and already fill in some of the properties (like the Project and Main class) based on main class you selected in the beginning. All properties shown here are the same as any standard Java program.


Tip:

Remember to change the name of your debug configuration to something meaningful.

Next click the Debug button on the bottom to start debugging your application.

After enabling the debugging, the application starts executing and will halt if any breakpoint is encountered. This can be a Drools rule breakpoint, or any other standard Java breakpoint. Whenever a Drools rule breakpoint is encountered, the corresponding .drl file is opened and the active line is highlighted. The Variables view also contains all rule parameters and their value. You can then use the default Java debug actions to decide what to do next (resume, terminate, step over, etc.). The debug views can also be used to determine the contents of the working memory and agenda at that time as well (you don't have to select a working memory now, the current executing working memory is automatically shown).

The Rule editor works on files that have a .drl (or .rule in the case of spreading rules across multiple rule files) extension.


The editor follows the pattern of a normal text editor in eclipse, with all the normal features of a text editor: