Drools environment preparation

From Training Material
Jump to navigation Jump to search

Version 7.10.0

Eclipse

Drools plugin

  • from Eclipse: Help > Install New Software... >
  • Paste this URL http://download.jboss.org/drools/release/7.10.0.Final/org.drools.updatesite/ and hit Enter
  • When the site loads, select the features to install, or click the Select All button.
  • To properly resolve all dependencies, check [x] Contact all update sites during install to find required software
  • Click Next, agree to the license terms, and install.

Drools runtime

  • Click OK > Apply and Close

New Drools Project

  • Choose File > New > Drools Project
  • Create a new project with example files and click Next.
  • Enter a project name, select the drools runtime created earlier, and select Add a sample HelloWorld rule file to this project. Click Finish.
  • Open the DroolsTest class that contains the main method. It is located in the package com.sample under src/main/java
  • Delete unnecessary code (Message class, and the message object related code)

Fact Model

  • Add a new Class (right click on com.sample package under src/main/java > New > Class)
  • Enter your class name and click Finish
  • Create fields, generate Getters and Setters (right click the editor and select Source > Generate Getters and Setters...)
  • Generate Constructor (right click the editor and select Source > Generate Constructor using Fields...)

Rules

  • Delete two rules related to the Message class from Sample.drl file
  • Change the import declaration and select your Class name, set the dialect
  • Write your first rule
  • Right click on the DroolsTest.java file and select Run as > Java Application
  • Create more complicated rules, and facts, insert them to the kSession, fireAllRules and have fun :)