Java 为什么将 Drools 6 KIE JAR 加载到代码中失败?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20995133/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 05:49:05  来源:igfitidea点击:

why does loading Drools 6 KIE JAR into code fail?

javajardroolsdrools-guvnorkie

提问by user3173088

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

我将 JBoss AS 7.1.1.Final 与 KIE Workbench/Drools 6.0.1.、Java 和 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

我需要 KIE Workbench(以前称为 Drools Guvnor)来让人们以图形方式创建/编辑带有事实和规则的 jar,然后将其作为 jar 存储在本地 maven 存储库中。这些罐子(以前是 pkg 的)我想以编程方式访问并将它们加载到我的 Drools 应用程序中。该应用程序甚至可以(尽管不是首选)在同一工作站上运行,因此可以访问存储库

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

a) 通过网址: 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

b) 通过文件路径/类路径: /my/folder/jboss-as-7.1.1.Final/bin/repositories/kie/com/myprojects/myProject/LATEST/myProject-LATEST.jar

I do NOTwant to create/compilerules 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.

希望创建/编译我的代码中动态地规则等,无论是动态加载一个.drl文件-准备好的罐子是我需要的负载,如与com.myprojects:myProject的:最新作标识。

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

我的问题是:为什么找不到来自 repo 的 jar?当我在 KIE WB 中创建它时,KieModule 不是 jar 和 jar 自动在 repo 中的表示吗?或者我必须更改 Maven Repo 的默认 ReleaseID,它打印出来

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?

这是Maven的问题吗?我怎么了?

Here the content of the jars pom.xml

这里是罐子 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:

我还尝试过使用此代码通过 URL 加载 jar:

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):

到目前为止我阅读的一些资源(不能发布其他 6 个):

add drls etc. dynamically

动态添加 drls 等

load drls dynamically

动态加载 drls

采纳答案by medveshonok117

In my case it turned out that

就我而言,结果证明

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

was missing in my POM

在我的 POM 中丢失