1
votes

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

1
What have you done so far?shazin
I am not getting how to call drools-guvnor 6 from java,We were using changeset.xml in drools 5.4 call from java, can you help me how to call drools 6.Ganesh
You should read the Workbench user guide. It explains all of this. In version 6, your rules are stored in a Maven repository and you define the dependency in your application, using KieScanner if you wish to have runtime reloading of rules.Steve
Thanks Steve, I go through with the document and I have doubt we can create project and deploy in drools guvnor . I have one silly question that what is equivalent to drols-guvnor of version 5.5.. Is it renamed as drools-workbench here.Ganesh

1 Answers

1
votes

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.