Try these notes - they are ONLY my notes, not a step by step on how to do it but it should give you some inspiration on how to tackle the issue. If it's still a problem, let me know and I'll do a step by step for you from scratch.
Drools Examples Porting Project Notes:
Notes:
This project is to take the stock V6 Drools examples and port them over to MyDroolsExamples Project for inclusion in my GitHub Repository.
This assumes you are using Eclipse with the Maven and Drools 6.x plugins installed, and you are at the point where you can run a Drools 6X hello world example app.
First - Create an stock Drools V6 Project w/Hello World Example, add in the external JAR: slf4j-jdk14-1.7.5.jar (
http://www.slf4j.org/download.html) to get the logging working correctly, test run as Java Application, and then convert to Maven project. Drools V6 is inherently Maven so this is a critical step, creates the important pom.xml file.
kModule.xml <== Find this file!!!
This is the file that tells drools where to find the Rules and how to name the XML references that load them Think Injection style IoC (Spring Like) infrastructure. It can also be done programatically.
The kmodule you need to use is located in the src/main/resources/META-INF directory
<?xml version="1.0" encoding="UTF-8"?>
<kbase name="rules" packages="rules">
<ksession name="ksession-rules"/>
</kbase>
</kmodule>
First Port
org.drools.examples.fibonacci
1. Clone the Packages for the Java and the Rules, copy over the Java Class and the DRL file in their respective places, and ammend the kmodule.xml file to be:
<?xml version="1.0" encoding="UTF-8"?>
<kbase name="rules" packages="rules">
<ksession name="ksession-rules"/>
</kbase>
<kbase name="org.drools.examples.fibonacci" packages="org.drools.examples.fibonacci">
<ksession name="FibonacciKS"/>
</kbase>
</kmodule>
Adding the KIE plugin to a Maven pom.xml -> A Source of problems
THIS:
<plugin>
<groupId>org.kie</groupId>
<artifactId>kie-maven-plugin</artifactId>
<version>${project.version}</version>
<extensions>true</extensions>
</plugin>
BECOMES THIS:
<plugin>
<groupId>org.kie</groupId>
<artifactId>kie-maven-plugin</artifactId>
<version>6.0.1.Final</version>
<extensions>true</extensions>
</plugin>
AFTER LOOKING HERE:
... and changing this: 6.0.1.Final
***> and then doing a Maven: Update Project execution
This is an important step to do often if you get wierd errors since it forces a refresh to the project.
Running the Java class gives me this:
SEVERE: Unknown KieSession name: FibonacciKS
Exception in thread "main" java.lang.NullPointerException
at org.drools.examples.fibonacci.FibonacciExample.main(FibonacciExample.java:31)
Therefore the kmodule.xml is incorrect ....
Researching Here:
This doc talks about the various ways a KBase can be built, and there are many ....
This is the code base for the examples....
SOLUTION:
This kmodule.xml is found under src/main/resources/META-INF/kmodule.xml
... once I added the highlighted XML extry it worked like a charm. The "kbase name" is the location of the RULES DRL,
the "ksession name" is the Java Class location.
So in this case it would be:
kbase name="org.drools.examples.fibonacci" src/main/resources/org.drools.examples.fibonacci
ksession name="FibonacciKS" src/main/java/org.drools.examples.fibonacci
<?xml version="1.0" encoding="UTF-8"?>
<kbase name="rules" packages="rules">
<ksession name="ksession-rules"/>
</kbase>
<kbase name="org.drools.examples.fibonacci" packages="org.drools.examples.fibonacci">
<ksession name="FibonacciKS"/>
</kbase>
<kbase name="org.drools.examples.backwardchaining" packages="org.drools.examples.backwardchaining">
<ksession name="HouseOfDoomKS"/>
</kbase>
<kbase name="org.drools.examples.honestpolitician" packages="org.drools.examples.honestpolitician">
<ksession name="HonestPoliticianKS"/>
</kbase>
<kbase name="org.drools.examples.golfing" packages="org.drools.examples.golfing">
<ksession name="GolfingKS"/>
</kbase>
<kbase name="org.drools.examples.shopping" packages="org.drools.examples.shopping">
<ksession name="ShoppingKS"/>
</kbase>
<kbase name="StateSalienceKB" packages="org.drools.examples.state.salience">
<ksession name="StateSalienceKS"/>
</kbase>
<kbase name="StateAgendaGroupKB" packages="org.drools.examples.state.agendagroup">
<ksession name="StateAgendaGroupKS"/>
</kbase>
<kbase name="org.drools.examples.cashflow" packages="org.drools.examples.cashflow">
<ksession name="CashFlowKS"/>
</kbase>
</kmodule>