为什么将 Drools 6 KIE JAR 加载到代码中失败? [英] why does loading Drools 6 KIE JAR into code fail?

查看:19
本文介绍了为什么将 Drools 6 KIE JAR 加载到代码中失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 JBoss AS 7.1.1.Final 与 KIE Workbench/Drools 6.0.1.、Java 和 Eclipse (Kepler) 一起使用.

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

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

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) 通过网址:http://localhost:8080/drools-wb-as7.0/maven2/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

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

不想想要在我的代码中创建/编译规则等,既不动态加载单个 .drl 文件 - 准备好的 jar 是我需要加载的, 和例如com.myprojects:myProject:LATEST 作为标识符.

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)

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

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

决定

org.default:artifact:1.0.0-SNAPSHOT ?

是 Maven 的问题吗?我做错了什么?

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

这里是 jars pom.xml 的内容

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>

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

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?

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

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

动态添加 drls 等

动态加载 drls

推荐答案

就我而言,结果是

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

在我的 POM 中丢失

was missing in my POM

这篇关于为什么将 Drools 6 KIE JAR 加载到代码中失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆