문제

I am using drools version 5.4 and I used url of changeset.xml to call the the drools-guvnor from my java code.

Now I am upgrading to drools 6.0 workbench version(Let me know if camel version is used), How can I call the drools workbench from my java code.

Thanks Ganesh Neelekani

도움이 되었습니까?

해결책

Everything in Drools 6 has become Mavenized. Instead of accessing a changeset.xml file you use the new Kie API to reference the Maven artifact that your rules are in.

First you would package your rules as a "kjar" (see this article for more info about kjars). Then, in your application you will need to add a the following dependency:

<dependency>
    <groupId>org.kie</groupId>
    <artifactId>kie-ci</artifactId>
    <version>${drools.version}</version>
</dependency>

Then, to dynamically load the rules at runtime, you use the replacement for the ResourceChangeScanner which is called the KieScanner

ReleaseId releaseId = KieServices.Factory.get().newReleaseId( "com.acme", "my-rules", "0.0.1-SNAPSHOT" );
KieContainer kc = KieServices.Factory.get().newKieContainer( releaseId );
KieScanner kscanner = KieServices.Factory.get().newKieScanner( kcontainer );
kscanner.scanNow() // this will dynamically resolve the rules artifact and build it

From that point on you can use the kcontainer you attached to that scanner to create KieSessions. By calling scanNow() you are telling the scanner to poll that artifact for changes. It will automatically build updates that it detects to that artifact. You can also force a rebuild by calling scanNow() again.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top