已安装流口水工作台 6.4.0 工作台中的最终和定义的指导规则。
如果我尝试从 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 天的时间解决这个问题。
它可能是您正在使用的网址,请尝试将其更改为:
http://ip:8080/drools-wb/maven2/org/mydemo/myDemo/1.0/myDemo-1.0.jar
即 maven2 不是 maven2b
然后在网络浏览器中尝试。如果您需要身份验证,那么当 Drools 托管在 Tomcat 上并打开基本身份验证时,这对我有用。
KieServices ks = KieServices.Factory.get();
KieResources resources = ks.getResources();
UrlResource urlResource = (UrlResource) resources.newUrlResource(url);
urlResource.setUsername("admin");
urlResource.setPassword("admin");
urlResource.setBasicAuthentication("enabled");
我发现这篇博文非常有帮助,即使您不使用Spring,它也可能对您有所帮助。
http://reypader.github.io/2016/01/06/spring-drools.html