JBoss.orgCommunity Documentation

Chapter 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

This chapter will cover the steps required to setup an executable sample Drools project in which rules can be used.

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

To create a new Drools project select FileNewDrools Project. This will open the New Drools Project wizard, as shown in the figure below.

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


Next you have the 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 click the Next button.


The 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, click 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 click the Create a new Drools 5 runtime button, select the folder where you want this runtime to be created and click the OK button.

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


Now click the Finish to complete the project creation.


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

Now let's look at the structure of the organized project. In the Package Explorer you should see the following:


The newly created project contains an example rule file Sample.drl in the src/main/rules directory and an example java file DroolsTest.java that can be used to execute the rules in a Drools engine in the folder src/main/java, in the com.sample package. All the others jar's that are necessary during execution are also added to the classpath in a custom classpath container called Drools Library.

Tip:

Rules do not have to be kept in Java projects at all, this is just a convenience for people who are already using Eclipse as their Java IDE.

Now we are going to add a new Rule package to the project.

You can either create an empty text .drl file or make use of the special New Rule Package... wizard to do it.

To open the wizard select FileNewRule Resource or use the menu with the JBoss Drools icon on the toolbar.


On the wizard page first select /rules as a top level directory to store your rules and type the rule name. Next specify the mandatory rule package name. It defines a namespace that groups rules together.


As a result the wizard generates a rule skeleton to get you started.