Wednesday, 31 August 2016

Installing Drools in Eclipse and Creating Simple Hello World Application in Drools

Drools

    • Drools is a Business rule management system
    • It is used to separate the data from logic.
    • It allow us to write logic (rules) in more layman readable form. This allow business people to create their own rules instead of depending on programmers and developers.

Rules

Rules are pieces of knowledge often expressed as, "When some conditions occur, then do some tasks."
The most important part of a Rule is it’s when part. If the when part is satisfied, the then part is triggered

Installing Drools in Eclipse

Drools comes with plugin for eclipse to create and manage the project from eclipse itself.

Prerequisites to install Drools Plugin:

  • Java 1.5 (or higher)
  • Eclipse 4.2

Installation Step

Drools Runtime

Drool runtime is needed to create and execute drool rules.
  • Click on Windows -> Preference -> Drools -> Installed Drools Runtime -> Add -> Browse.
  • Browse to the downloaded binaries folder and Add.

Example Project

  1. File -> New -> Drool Project -> Create an empty project.
  2. Enter project name -> finish.
  3. The project follow maven folder structure. Two primary folder are
    1. src/main/java – Java code would go here.
    2. src/main/resources – Drool files would go here.
  4. Create a new java class file in src/main/java. Say ‘Hello.java’ in package ‘com.example’.
  5. Create a new drool file in src/main/resources/rules. Say ‘ReplaceHello.drl’.
  6. Result.
Apart from creating the rules file in resources folder, we can import the rules files from classpath as well as file system. Below example show an example of reading the rule file from classpath.

No comments:

Post a Comment