1
votes

I'm using Kie, I want to execute all the .drl files in a directory. is there any simpler way ??...

Folder Structure:

1. /drools/rules/rule_1.drl
2. /drools/rules/rule_2.drl
3. /drools/rules/rule_3.drl
4. /drools/rules/rule_4.drl

ResourceFactory.newFileResource(drlFile))

I have used the above code to load a single file to kieSession.

Expected: Is there any simple way to load all the files in a directory to kieSession

1
Did you try creating a kmodule and specify your directory so all the rules files in that package/directory will be loaded in the ksession. Reference: Drools+SpringBoot - Rupesh

1 Answers

1
votes

You need a kmodule.xml file in your resources folder, like this:

resources -> META-INF -> kmodule.xml

Very important to have this structure. In the META-INF folder you also need to have the following directory:

resources -> META-INF -> maven -> pom.properties

Otherwise working with the kmodule.xml file does not work.

Your definition of the kmodule.xml file would be something like this:

<?xml version="1.0" encoding="UTF-8"?>
<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
    <kbase name="mypackage" packages="drools.rules">
        <ksession name="mysession" type="stateless"/>
    </kbase>
</kmodule>

If you use packages instead of files, the container could be created in this way:

this.kieContainer = this.kieServices.getKieClasspathContainer();

You would then be able to to create a, for example, stateless session in this way:

StatelessKieSession statelessKieSession = kieContainer.newStatelessKieSession("mysession"); 

If you need the kieBase for whatever reason, you use:

kieBase = statelessKieSession.getKieBase();