问题
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:
- Build the Drool project that you want to use in the other Drool Project. Before building properly check the
kmodule.xmlfile. - After building the project use
mvn file uploadcommand to upload the jar into thelocal maven repositoryi.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. - Then add the above custom groupId,artifactId and version in the
pom.xmlas a dependency. 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