Java version 1.5 and higher is required to run the examples in this book. Drools can be downloaded from http://www.jboss.org/drools/downloads.html. You'll need the Binaries and IDE downloads. The latter is the Drools Eclipse plugin. It helps with writing rules. The Drools 'new project' wizard in Eclipse can create a simple Drools project that is ready to run. When setting up a new project, you need to tell it the location of the 'Drools Runtime' (where you extracted the Drools binaries).
If for some reason the Eclipse plugin is not an option, Drools can be set up by maven or manually. When using maven add the following dependencies to your project's pom.xml
file:
<dependencies> <dependency> <groupId>org.drools</groupId> <artifactId>drools-api</artifactId> <version>${drools.version}</version> </dependency> <dependency> <groupId>org.drools</groupId> <artifactId>drools-core</artifactId> <version>${drools.version}</version> </dependency> <dependency> <groupId>org.drools</groupId> <artifactId>drools-compiler</artifactId> <version>${drools.version}</version> </dependency> </dependencies> <properties> <drools.version>5.0.1</drools.version> </properties>
Code listing 1: Drools dependencies in a maven's pom.xml
file.
By adding these dependencies into your project's pom
file, we're declaring that our project depends on three libraries: drools-api
, drools-code
, and drools-compiler
. Depending on the features used, we may need to add or remove some Drools libraries. Please note the drools.version
property, which is set to version 5.0.1. You may need to change it depending on the latest available release.
We also have to tell maven where to get these libraries. They can be downloaded from the official JBoss maven repository which is located at http://repository.jboss.com/maven2/. The following code snippet does the trick:
<repositories> <repository> <id>JBoss Repository</id> <url>http://repository.jboss.com/maven2/</url> <snapshots> <enabled>false</enabled> </snapshots> <releases> <enabled>true</enabled> </releases> </repository> </repositories>
Code listing 2: JBoss maven repository in a maven's pom.xml
file.
Note that the latest snapshot releases can be downloaded from http://snapshots.jboss.org/maven2/.
Let's now look at the libraries that are needed in more detail.
JBoss Rules/Drools is licensed under Apache License, Version 2.0 (ASL is a free software license that allows us to develop free, open source as well as proprietary software. Its contents can be found at http://www.apache.org/licenses/LICENSE-2.0.html). In order to run the examples in this book, at least the following libraries will be needed on the Java classpath:
antlr-runtime-3.1.1.jar
: A parser generator—helps with parsing rule files (licensed under ANTLR 3 License, which is based on The BSD License).core-3.4.2v_883_R34x.jar
: Generic Eclipse Java compiler—it's a part of Eclipse Java Development Tools (licensed under the Eclipse Public License v1.0).drools-api-5.0.1.jar
: Drools user API or also known as the public API—most of the classes we'll be dealing with are located here (licensed under ASL).drools-compiler-5.0.1.jar
: Knowledge compiler—understands rule syntax and compiles rules into Java classes (licensed under ASL).mvel-2.0.10.jar
: mvel is the property extraction and expression language for Java. Some core Drools features are implemented using mvel and it is also used as a dialect in the rule language (licensed under ASL).drools-core-5.0.1.jar
: The Drools engine itself (licensed under ASL).
These libraries are valid for Drools version 5.0.1. Please note that you may need different versions of these libraries depending on your version of Drools. After downloading the binary distribution of Drools (for example, drools-5.0-bin.zip
file) and extracting it, the file README_DEPENDENCIES.txt
provides more details on what libraries are actually needed for specific features. Note that all third party libraries are stored under the lib
folder.