Inside the bootstrapDrools() method we can start using it straight away. Because CDI (Weld) is creating the instance of our class App it is able to Inject a new instance of our KieSession. The main(…) method is bootstrapping Weld and then calling our App.boostrapDrools() method. Boostrap the CDI container, in this case WELDĪpp app = wc.instance().select(App.class).get() Int rulesFired = kSession.fireAllRules() The KieSession was injected so we can use it now Our App.java class should look like this now: Weld is the CDI reference implementation, but in theory you can use any other CDI implementation. Because CDI is only a set of APIs we need also to provide an implementation of these interfaces and that’s why we specified weld-se-core as our CDI container. CDI stands for Context and Dependency Injection and it is basically a standard set of APIs that allows us to benefit from the power of Dependency Injection inside our applications.
Let’s go to the App.java class that was generated automatically by the Maven Archetype. Once we get our dependencies in place we can start using Drools straight away. The pom file after editing should look like this:Īt this point I’ve deleted the Junit Test generated by the Archetype that was based on JUnit 3.x. Notice that Drools 6.3.0.Final is already in the central maven repository so no need of adding an extra repository.
We now need to update the pom.xml file to add the specific drools dependencies. The project structure will look like this: Maven Project Structure Define value for property ‘package’: : : Īfter this the project will be create and ready to be opened in your favourite IDE.Define value for property ‘version’: 1.0-SNAPSHOT: :.Define value for property ‘artifactId’: : my-first-drools-project.Define value for property ‘groupId’: :.This will create a new maven empty project by asking you the basic information about GroupId, ArtifactId and Version Let’s start simple, let’s create a Maven empty project by using the following Maven Goal: mvn archetype:generate -DarchetypeGroupId= -DarchetypeArtifactId=maven-archetype-quickstart (You can find the sources of this project here: ) In order to get started you need to have the following already installed in your environment: I will also be using the CDI capabilities provided by Drools 6.3.0.Final.
In this short post I will show how to create a very simple Drools enabled Maven project. I was creating some material for my next Workshop in South America when I thought, let’s create some blog posts about the main topics, so I can share with all of you some basic tutorials that should help you to get started with the latest version of Drools.