why does loading Drools 6 KIE JAR into code fail?

匿名 (未验证) 提交于 2019-12-03 01:57:01

问题:

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

4.0.0com.myprojectsmyProjectLATESTmyProjectguvnor-m2-repoGuvnor M2 Repohttp://localhost:8080/drools-wb-as7.0/maven2/

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

回答1:

In my case it turned out that

org.kiekie-ci

was missing in my POM



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!