I am a beginner with Drools and Maven and I am facing a problem to load rules with KieScanner.
The aim of the project is to be able to dynamically load rules in a permanent KieSession. I wonder if it is possible to manage rules with the KieFileSystem (not sure it is possible without a dispose of the session and starting another one leading to the lack of the previous inserted facts), but the good way is to use KieScanner.
It seems this requires the creation of a Jar containing the rules and having a Maven ID (ReleaseId), but I could not find detailed documentation about creation of these Jar files.
Which files shall be included in such a Jar ? DRL files, Pom.xml and manifest.mf ?
Where can this Jar file be added ? According to documentation it should not be added in the classpath when the detection of new issues of that file is necessary : "once a module is on the classpath, no other version may be loaded dynamically".
Is a Maven command needed ?
Can someone give me information on those points or give me a link where creation and deployment of such a Jar and its management in a KieScanner is described ? Thanks a lot.
Here is an example to use MemoryFileSystem to create KJar and use it to create KieContainer
Input:
Thanks a lot for your response raphaëλ. But my problem was rather building the jar before being able to use it in Java code.
This is how I could solve my problem.
Creation of a kjar file with the rules :
command :
jar cvmf META-INF\MANIFEST.MF example-rules.jar META-INF* rules*
Example of file kmodule.xml :
File MANIFEST.MF :
Add kjar to Maven repository :
command :
mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=example-rules.jar -DpomFile=pom_jar.xml
file pom_jar.xml is used to define Maven references, example of such a file :
Any comment is welcome.
Here is an example of a stateless
kiesession
using a kjar from a maven repository (code is in scala, but i am sure you'll get the idea of you primarily program in Java)This looks for a kjar using maven with the gav
com.piedpiper:demo:[1.0,2)
(iow any version from1.0
to2
(non-inclusive). It checks every two seconds if a new version within that range is available.The kjar contains the knowledge resources, the
kmodule.xml
etc (a proper kjar with the compiled rules using thekie-maven-plugin
plugin-extension ). In this case it also contains the fact model (i would normally separate that out in a different maven artefact.)The rule used in the example above is
When changing the rule to for example
> 15
, it takes 2 seconds to become operational.