Book Image

Drools JBoss Rules 5.0 Developer's Guide

By : Michal Bali
Book Image

Drools JBoss Rules 5.0 Developer's Guide

By: Michal Bali

Overview of this book

<p>Business rules can help your business by providing a level of agility and flexibility. As a developer, you will be largely responsible for implementing these business rules effectively, but implementing them systematically can often be difficult due to their complexity. Drools, or JBoss Rules, makes the process of implementing these rules quicker and handles the complexity, making your life a lot easier!<br /><br />This book guides you through all of the features of Drools, such as dynamic rules, the event model, and Rete implementation with high performance indexing. It will help you to set up the JBoss Rules platform and start creating your own business. It's easy to start developing with Drools if you follow its real-world examples that are intended to make your life easier.<br /><br />Starting with an introduction to the basic syntax that is essential for writing rules, the book will guide you through validation and human-readable rules that define, maintain, and support your business agility. As a developer, you will be expected to represent policies, procedures and. constraints regarding how an enterprise conducts its business; this book makes it easier by showing you it can be done.<br /><br />A real-life example of a banking domain allows you to see how the internal workings of the rules engine operate. A loan approval process example shows the use of the Drools Flow module. Parts of a banking fraud detection system are implemented with Drools Fusion module, which is the Complex Event Processing part of Drools. This in turn, will help developers to work on preventing fraudulent users from accessing systems in an illegal way.<br /><br />Finally, more technical details are shown on the inner workings of Drools, the implementation of the ReteOO algorithm, indexing, node sharing, and partitioning.</p>
Table of Contents (22 chapters)
Drools JBoss Rules 5.0 Developer's Guide
Credits
Foreword
About the Author
About the Reviewers
Preface
Development Environment Setup
Custom Operator
Dependencies of Sample Application
Index

Environment setup


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.

Dependencies and their licenses

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.