Drools add rules from another project into kmodule?

大憨熊 提交于 2020-05-14 10:12:17

问题


So the docs state that you can load kie modules programatically with

KieServices ks = KieServices.Factory.get();

KieContainer kieContainer = newKieContainer(ks.newReleaseId("my.org","my.artifact.id","version"));
KieSession kieSession = kieContainer.newKieSession("ktest");

Is there a way to do that through maven and the kmodule.xml? My use case would be to use the rules I wrote in this project, in another project and add onto them. Maybe I missed it in the 7.7 docs, if so please link and I'll set an appointment with my eye doctor.

Addendum: I imagine the kmodule.xml to look similar to this:

<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
<configuration>
</configuration>
<!-- Shared Knowledgebase -->
<kbase name="am" packages="my.package.name, rules">  
    <ksession name="default" type="stateful" default="true"/>
</kbase>

However that does not seem to see the package

Thanks


回答1:


Yes, you can use a different Drools project in another Project. Follow the following steps:

  1. Build the Drool project that you want to use in the other Drool Project. Before building properly check the kmodule.xml file.
  2. After building the project use mvn file upload command to upload the jar into the local maven repository i.e .m2 repository. Example - mvn install:install-file -Dfile="pathToJAr" -DgroupId="groupId" -DartifactId="artifactId" -Dversion="version" -Dpackaging="jar". You can use your custom groupId,artifactId, and version.
  3. Then add the above custom groupId,artifactId and version in the pom.xml as a dependency.
  4. Then create kieConatinerand kieSession like follow:

    KieServices.Factory.get(); ReleaseId rs= ks.newReleaseId("artifactId","groupId","version"); KieContainer kieContainer = ks.newKieContainer(rs); KieScanner kieScanner = ks.newKieScanner(kieContainer); kieScanner.start(10000);

KieScanner is used to dynamically update the KieContainer. Here kieScanner will scan the local maven repo every 10 sec.




回答2:


So I did figure this out. I thought it had something to do with package in the kmodule.xml. But in actuality it was simply adding the incluldes = "package.name" and it figured it out all on its own.

However, I also recommend @Prog_G answer as well, though it was not what I was looking for, I'm sure it will help others with this same question.

final result:

<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
<configuration>
</configuration>
<kbase name="am" packages="rules" includes = "my.package.name">  
    <ksession name="default" type="stateful" default="true"/>
</kbase>


来源:https://stackoverflow.com/questions/50843133/drools-add-rules-from-another-project-into-kmodule

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!