Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why does loading Drools 6 KIE JAR into code fail?

I'm using JBoss AS 7.1.1.Final with KIE Workbench/Drools 6.0.1., Java and Eclipse (Kepler).

I need KIE Workbench (formerly Drools Guvnor) to let people graphically create/edit jars with Facts and Rules and then store as jars in the local maven repository. These jars (formerly pkg's) i want then to access programatically and load them into my Drools application. The app could even (although not preferedly) be run on the same workstation, so access to the repository could be

a) by URL: http://localhost:8080/drools-wb-as7.0/maven2/com/myprojects/myProject/LATEST/myProject-LATEST.jar

b) by filepath/classpath: /my/folder/jboss-as-7.1.1.Final/bin/repositories/kie/com/myprojects/myProject/LATEST/myProject-LATEST.jar

I do NOT want to create/compile rules etc in my code, neither dynamically load a single .drl file dynamically - the prepared jar is what i need to load, with e.g. com.myprojects:myProject:LATEST as identifier.

I try this (according to documentation)

KieServices ks = KieServices.Factory.get();
KieContainer kContainer = ks.newKieContainer(
ks.newReleaseId("com.myprojects",   "myProject", "LATEST"));
KieScanner kScanner = ks.newKieScanner( kContainer );
kScanner.start( 10000L );

KieSession kSession = kContainer.newKieSession("defaultKieSession");
kSession.insert( fact );

[...]

However, this fails with the Runtime Exception,

Exception in thread "main" java.lang.RuntimeException: Cannot find KieModule: com.myprojects:myProject:LATEST
        at org.drools.compiler.kie.builder.impl.KieServicesImpl.newKieContainer(KieServicesImpl.java:86)
        at com.myprojects.myproject.KieDroolsWBOnlinePuller.code(KieDroolsWBOnlinePuller.java:118)
        at com.myprojects.myproject.KieDroolsWBOnlinePuller.main(KieDroolsWBOnlinePuller.java:40)

My question is: Why is the jar from repo not found? Isn't the KieModule the representation of the jar and the jar automatically in the repo as I created it within KIE WB? Or must I change the default ReleaseID of the Maven Repo, which printed out with

KieRepository repo = ks.getRepository();
repo.getDefaultReleaseId()

resolves to

org.default:artifact:1.0.0-SNAPSHOT ?

Is it a Maven problem? What am I getting wrong?

Here the content of the jars pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.myprojects</groupId>
  <artifactId>myProject</artifactId>
  <version>LATEST</version>
  <name>myProject</name>
  <repositories>
    <repository>
      <id>guvnor-m2-repo</id>
      <name>Guvnor M2 Repo</name>
      <url>http://localhost:8080/drools-wb-as7.0/maven2/</url>
    </repository>
  </repositories>
</project>

What I also tried was using this code to load the jar by URL:

KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId("com.myprojects", "myProject", "LATEST");
KieResources kres = ks.getResources();

String url = "http://127.0.0.1:8080/drools-wb-as7.0/maven2/com/myprojects/myProject/LATEST/myProject-LATEST.jar";
kres.newUrlResource( url );
KieContainer kContainer = ks.newKieContainer(releaseId);
KieSession kSession = kContainer.newKieSession("statelessDefautlKnowledgeSession");
[...]

This failed with the same exception.... Any ideas?

Some Resources I read so far (can't post the other 6):

add drls etc. dynamically

load drls dynamically

like image 338
user3173088 Avatar asked Jan 08 '14 12:01

user3173088


1 Answers

In my case it turned out that

<dependency>
  <groupId>org.kie</groupId>
  <artifactId>kie-ci</artifactId>
</dependency>

was missing in my POM

like image 127
m c Avatar answered Nov 02 '22 11:11

m c