JBoss.orgCommunity Documentation
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.
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.
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.
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 follow to File > New > Rule 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 it's mandatory to specify the rule package name. It defines a namespace that groups rules together.
As a result the wizard generates a rule skeleton to get you started.