在工作台中安装了 drools workbench 6.4.0 Final 并定义了指导规则。
如果我试图从 java 应用程序执行规则,则会出现以下异常。
Exception in thread "main" java.lang.RuntimeException: Cannot find KieModule: org.mydemo:myDemo:1.0
at org.drools.compiler.kie.builder.impl.KieServicesImpl.newKieContainer(KieServicesImpl.java:117)
at org.drools.compiler.kie.builder.impl.KieServicesImpl.newKieContainer(KieServicesImpl.java:111)
at com.test.Test.main(Test.java:51)
关注了在线资源和相关问题,但仍然无法解决问题。
这是相关链接之一。
我的 java 项目依赖项和配置文件。
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-ci</artifactId>
<version>6.4.0.Final</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-compiler</artifactId>
<version>6.4.0.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-core</artifactId>
<version>6.4.0.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-internal</artifactId>
<version>6.4.0.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-api</artifactId>
<version>6.4.0.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-templates</artifactId>
<version>6.4.0.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-decisiontables</artifactId>
<version>6.4.0.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.3</version>
<scope>provided</scope>
</dependency>
<profile>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>guvnor-m2-repo</id>
<name>Guvnor M2 Repo</name>
<url>http://ip:8080/drools-wb/maven2/</url>
</repository>
</repositories>
</profile>
我的Java代码在这里:
public static void main(String[] args) {
String url = "http://ip:8080/drools-wb/maven2wb/org/mydemo/myDemo/1.0/myDemo-1.0.jar";
// make sure you use "LATEST" here!
ReleaseIdImpl releaseId = new ReleaseIdImpl("org.mydemo", "myDemo", "1.0");
KieServices ks = KieServices.Factory.get();
ks.getResources().newUrlResource(url);
KieContainer kieContainer = ks.newKieContainer(releaseId);
// check every 5 seconds if there is a new version at the URL
KieScanner kieScanner = ks.newKieScanner(kieContainer);
kieScanner.start(5000L);
// alternatively:
// kieScanner.scanNow();
Scanner scanner = new Scanner(System.in);
while (true) {
runRule(kieContainer);
System.out.println("Press enter in order to run the test again....");
scanner.nextLine();
}
}
private static void runRule(KieContainer kieKontainer) {
StatelessKieSession kSession = kieKontainer.newStatelessKieSession("testSession");
kSession.setGlobal("out", System.out);
kSession.execute("testRuleAgain");
}
谁能帮助我,我是流口水的新手,花了将近 2 天的时间来解决这个问题。