Drools Program using Maven dependency

Now we are going to explain how to create drools project with maven dependency. First, we will create simple Spring template project where we will inject Drools programming.

Here are few easy steps to create Spring Template Project

  • GoTo  File>New>Spring Template Project like below:-


After Spring Template Project selection from above screen, new prompted screen will come where you need to select Spring MVC Project and click on Next button


Now write project name and provide the top level package structure and click on Finish.


Now you can see Spring MVC project created in your workspace. Project structure is going to look like below:-


Don’t think of auto generated classes. Since we have chosen Spring MVC Project , these classes got created by default to accommodate Spring MVC feature.

Now we will add maven dependency and write Drools program for the following simple requirement:-

Create a drools program which modifies customer name as “Modified Name” if the name of the customer is “SimplifiedTutorials”.

1.) Add maven dependency

Before creating any class or .drl file, first, we need to add maven dependency for Drools so that required classes get added into your project. Now add dependency in pom.xml

Now build the project using mvn clean install command.

2.) Classes need to be created for above requirement

  • we need to create one .drl file, which will contain the business logic of checking the name.
  • One java class as model to pass data to the .drl file
  • One more java class with the main method for executing .drl file.

Here is model class to hold name and age of the employee



DRL File

This file will contain all the business logic to check the name


Now right click and run TestDrools.java class. You should get output as below:-


Leave a Reply

Your email address will not be published. Required fields are marked *