In this short tutorial we will learn how to create a Drools Project using Maven's kie-drools-archetype.

I've seen in many forums the questions which is the archetype for creating a Drools project. As you can see from the Maven's repository ( the correct archetype is the following one (in its latest version):


Let's try it!

mvn archetype:generate -B -DarchetypeGroupId=org.kie -DarchetypeArtifactId=kie-drools-archetype -DarchetypeVersion=7.7.0.Final -DgroupId=com.mastertheboss -DartifactId=drools-project -Dversion=1.0-SNAPSHOT -Dpackage=drools.project

The above command will create the drools-project folder with a Maven project. Let's check that everything is in order:

tree drools-project/
├── pom.xml
└── src
    ├── main
    │   ├── java
    │   │   └── drools
    │   │       └── project
    │   │           └──
    │   └── resources
    │       ├── META-INF
    │       │   └── kmodule.xml
    │       └── rules.drl
    └── test
        ├── java
        │   └── drools
        │       └── project
        │           └──
        └── resources

The archetype has create a very basic Rule file (rules.drl) which loads a simple Fact in it:

package drools.project;

global java.util.Set controlSet;

rule "will execute per each Measurement having ID color"
	Measurement( id == "color", $colorVal : val )

A Test class is included in the Archetype, which will insert into a KieSession new Measurement. Then it fires the Rule and expects that the Session contains the three different kind of Measurement inserted:

package drools.project;

import static org.junit.Assert.*;

import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import org.drools.core.time.SessionPseudoClock;
import org.junit.Test;
import org.kie.api.KieBase;
import org.kie.api.KieBaseConfiguration;
import org.kie.api.KieServices;
import org.kie.api.builder.Message;
import org.kie.api.builder.Results;
import org.kie.api.conf.EventProcessingOption;
import org.kie.api.definition.KiePackage;
import org.kie.api.definition.rule.Rule;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.KieSessionConfiguration;
import org.kie.api.runtime.conf.ClockTypeOption;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RuleTest {
    static final Logger LOG = LoggerFactory.getLogger(RuleTest.class);

    public void test() {
        KieServices kieServices = KieServices.Factory.get();

        KieContainer kContainer = kieServices.getKieClasspathContainer();
        Results verifyResults = kContainer.verify();
        for (Message m : verifyResults.getMessages()) {
  "{}", m);
        }"Creating kieBase");
        KieBase kieBase = kContainer.getKieBase();"There should be rules: ");
        for ( KiePackage kp : kieBase.getKiePackages() ) {
            for (Rule rule : kp.getRules()) {
      "kp " + kp + " rule " + rule.getName());
        }"Creating kieSession");
        KieSession session = kieBase.newKieSession();"Populating globals");
        Set<String> check = new HashSet<String>();
        session.setGlobal("controlSet", check);"Now running data");

        Measurement mRed= new Measurement("color", "red");

        Measurement mGreen= new Measurement("color", "green");

        Measurement mBlue= new Measurement("color", "blue");
        session.fireAllRules();"Final checks");

        assertEquals("Size of object in Working Memory is 3", 3, session.getObjects().size());
        assertTrue("contains red", check.contains("red"));
        assertTrue("contains green", check.contains("green"));
        assertTrue("contains blue", check.contains("blue"));


In order to build and test the project, the following pom.xml has been included, which uses drools-bom to handle the Drool dependencies version (in this example 7.7.0.Final).

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">










That's all. Compile and build the project with:

$ mvn clean install test

And see it in action in the following Drools screen cast:

Continue Learning Drools through the following tutorials:

1) Coding Rules in Decision Tables

In Drools, Decision Tables are a way to generate rules from the data entered into a spreadsheet. The spreadsheet can be a standard Excel (XLS) or a CSV File.

Drools decision tables example

If you want to learn how to code your Rules into an excel Spread Sheet, keep reading this tutorial: Getting started with Decision Tables in Drools

2) Getting started with the Kie Execution Server

The Kie Server is a Java web application that allow us to expose rules and business process to be executed remotely using REST and JMS interfaces. The following tutorial shows how to install it on the top of WildFly: Configure Kie Execution Server on WildFly

3) Deploy your assets on the Business Central

Once that you are familiar with the Kie Execution Server, you can learn how install also the Business Central where you can design, build and deploy your assets. Here is the tutorial for you: Getting started with Business Central Workbench