JBoss.orgCommunity Documentation
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 New Drools Project wizard, as shown in the figure below.
→ → . This will open theOn the first page type the project name and click the
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
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
link.You should see the Preferences window where you can configure the workspace settings for Drools runtimes. To create a new runtime, click the 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 click the
button, select the folder where you want this runtime to be created and click the button.You will see the newly created runtime show up in your list of Drools runtimes. Check it and click the
button.Now click the
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.
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
→ → 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.