Loading kjar from classpath

508 views
Skip to first unread message

Priyanka

unread,
May 3, 2017, 7:44:18 AM5/3/17
to Drools Development
Dear community,

In my usecase, I want to accept path of knowledge jar files and then load them in drools container to start stateless session.
I could load the rules using classloader. But I am confused how to start a session using this container.

This is sample code:

ClassLoader cl = addkjarToClasspath(rulesDir);
KieContainer kieContainer = KieServices.Factory.get().newKieClasspathContainer(cl);
kieSession = kieContainer.newStatelessKieSession();

This works well as long as we have only one kmodule in our classpath. When we have multiple modules, I think we should initialize container by providing the releaseId of selective kjar.

My questions,
1. How do you provide releaseId of a particular kjar when using KieClasspathContainer?
2. In above code if I provide sessionName, it fails to load the session with only name as input.
3. When I try to get KieBase from container, provided base name it fails, when I mark base as default it can pick it. But again when you have multiple of base it picks one randomly.

Please suggest me what is the best way of creating KieStateless session when you want to load you session from classpath?

-Priyanka

llev...@redhat.com

unread,
May 4, 2017, 10:34:45 AM5/4/17
to Drools Development
The releaseId (groupId + artifactId + version, aka GAV) information is inherently Maven oriented. In order to pickup a kjar from the class path, using a specific releaseId, would require that you write code that reads the GAV out of each kjar in the class path.
Is there a reason that you want to class path container loading, as opposed to loading kjars from a Maven repository?

In answer to your questions...
1. This isn't available without writing code additional code
2. You didn't ask a question, but I'll surmise that you meant to ask why it isn't loading your named session. Without more information, the best guess I can come up with is that the session name you are providing doesn't match the name of a session defined in the kmodule.xml file contained in your kjar
3. Again, without more information it is difficult to know what is causing the issue. Can you provide a small sample that reproduces the issue? In particular, the kmodule.xml file would be helpful.

~ Lance Leverich

Priyanka

unread,
May 5, 2017, 4:53:19 AM5/5/17
to Drools Development


On Thursday, May 4, 2017 at 8:04:45 PM UTC+5:30, llev...@redhat.com wrote:
The releaseId (groupId + artifactId + version, aka GAV) information is inherently Maven oriented. In order to pickup a kjar from the class path, using a specific releaseId, would require that you write code that reads the GAV out of each kjar in the class path.
Is there a reason that you want to class path container loading, as opposed to loading kjars from a Maven repository?
The reason is, my kjar are going to be on hdfs or some other file system and not on local fs. It's not possible for me to use maven repository.
 
In answer to your questions...
1. This isn't available without writing code additional code
Can you please suggest what extra code I have to write?
2. You didn't ask a question, but I'll surmise that you meant to ask why it isn't loading your named session. Without more information, the best guess I can come up with is that the session name you are providing doesn't match the name of a session defined in the kmodule.xml file contained in your kjar
The session name was as per declared in kmodule.xml, only thing is I didn't load any particular kiebase or kiemodule using GAV. I though as it has loaded all kmodule files, it would auto discover session based on name. But it didn't. 
3. Again, without more information it is difficult to know what is causing the issue. Can you provide a small sample that reproduces the issue? In particular, the kmodule.xml file would be helpful.
This is kmodule.xml I used:

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

I had one more kjar having similar kmodule (different kbase and ksession name), but also marked as default.

Priyanka

unread,
May 5, 2017, 4:54:50 AM5/5/17
to Drools Development
Sorry messup up formating of previous reply. Please find my response inline.

Ravi Vanamala

unread,
Sep 25, 2018, 12:49:16 PM9/25/18
to Drools Development
Hi,

I am using drools 6.4.0 Final version and facing the same issue. Did you find any solution or workaround on this issue? 

Thanks!

~Ravi 

Priyanka

unread,
Sep 26, 2018, 3:00:15 AM9/26/18
to Drools Development
Yes, There are 2 ways you can do it:
1. Just before you start ur drools copy the jar from hdfs to local, in classpath location, and load it as local jar.
2. If you have rule files on hdfs dir, use hdfs FS stream read the contents in memory and load the session.

Also you can take config as kiebaseName, kieSessionName and load the right session when you have multiple loaded.

Ravi Vanamala

unread,
Sep 27, 2018, 3:52:10 AM9/27/18
to Drools Development

Thanks for the quick response!

Have you still managed to work with getKieClasspathContainer() without providing any ReleaseId??

I have a scenario like projectA(A.jar) has some rules and kmodule.xml bundled as A.jar file and there another projectB(B.jar) having its own kmodule.xml. 
projectB(B.jar) required A.jar as dependency and provided in classpath. 

The issue here is... projectB kmodule.xml (KieModule) is added/loaded to the KieContainer and followed by projectA aka A.jar kmodule.xml (KieModule) is added/loaded and overridden projectB KieModule as the both the KieModules having the same Default ReleaseId, so the issue.

I am just curious...would you mind to provide sample code snippet or throw some light on this?


~Ravi

Ravi Vanamala

unread,
Oct 1, 2018, 10:41:48 AM10/1/18
to Drools Development
I found a way to override the pom.properties to define the releaseId unique for every kmodule.xm (KieModule) so that can avoid defaultGAV and also avoid the conflicts. Still I am good with getKieClasspathContainer().

~Ravi
Reply all
Reply to author
Forward
0 new messages