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.
ClipCapIt-180914-095701.PNG

Drools runtime

ClipCapIt-180914-101253.PNG
  • Click OK > Apply and Close
ClipCapIt-180914-101511.PNG

New Drools Project

  • Choose File > New > Drools Project
  • Create a new project with example files and click Next.
ClipCapIt-180914-102727.PNG
  • Enter a project name, select the drools runtime created earlier, and select Add a sample HelloWorld rule file to this project. Click Finish.
ClipCapIt-180914-102957.PNG
  • 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)
ClipCapIt-180914-103815.PNG

Fact Model

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

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
ClipCapIt-180914-110658.PNG
  • 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 :)