我们尝试使用全新的KIE工作台(以前称为Guvnor)和新的基于maven的工件切换到Drools 6.
现在,我想在第二个映像(“部署”)中使用this blog post中描述的系统:通过HTTP从工作台存储库加载规则(虚线箭头,从左侧的HTTP直接进入应用程序).
问题是,我不知道如何将工件加载到我的KieServices / KieModule对象中.我基本上不想使用maven,我也无法全局提供maven的settings.xml作为Java参数的路径,所以这个选项已经出来了.
我认为类似的问题是this one.正如那里提到的,我也尝试加载一个URL资源,但问题似乎是系统无法确定给定URL的ResourceType是什么样的(http:// localhost:8080 / kie) -drools / maven2 /…/- 1.0.0.jar)是.是的,我可以直接从浏览器访问存储库中的.jar,无需身份验证.
任何想法或教程如何做到这一点?
我的测试代码:
public static void main(String[] args) { KieServices ks = KieServices.Factory.get(); KieRepository repo = ks.getRepository(); String url = "http://localhost:8080/kie-drools/maven2/de/test/test/1.0.0/test-1.0.0.jar"; Resource urlResource = ks.getResources().newUrlResource(url); KieModule kModule = repo.addKieModule(urlResource); // this already fails }
错误:
Exception in thread "main" java.lang.RuntimeException: Unable to fetch module from resource :[UrlResource path='http://localhost:8080/kie-drools/maven2/de/itm/Herma400/1.0.1/Herma400-1.0.1.jar'] at org.drools.compiler.kie.builder.impl.KieRepositoryImpl.getKieModule(KieRepositoryImpl.java:205) at org.drools.compiler.kie.builder.impl.KieRepositoryImpl.addKieModule(KieRepositoryImpl.java:161) at kieTest.MainKieTest.main(MainKieTest.java:24) Caused by: java.lang.NullPointerException at org.drools.compiler.kie.builder.impl.ClasspathKieProject.getPomProperties(ClasspathKieProject.java:197) at org.drools.compiler.kie.builder.impl.ClasspathKieProject.fetchKModule(ClasspathKieProject.java:148) at org.drools.compiler.kie.builder.impl.ClasspathKieProject.fetchKModule(ClasspathKieProject.java:109) at org.drools.compiler.kie.builder.impl.KieRepositoryImpl.getKieModule(KieRepositoryImpl.java:190) ... 2 more
提前致谢!
解决方法
我终于设法解决了这个问题.下面是一个工作示例,它通过HTTP从KIE存储库加载Drools工件并执行规则:
package kieTest; import java.util.Scanner; import org.drools.compiler.kproject.ReleaseIdImpl; import org.kie.api.KieServices; import org.kie.api.builder.KieScanner; import org.kie.api.runtime.KieContainer; import org.kie.api.runtime.StatelessKieSession; public class MainKieTest { public static void main(String[] args) { // works even without -SNAPSHOT versions String url = "http://localhost:8080/kie-drools/maven2/de/test/Test/1.2.3/Test-1.2.3.jar"; // make sure you use "LATEST" here! ReleaseIdImpl releaseId = new ReleaseIdImpl("de.test","Test","LATEST"); 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"); } }
> http://www.skills421.com/tutorials-drools-components.jsp
> http://blog.athico.com/2013/12/deployment-with-drools-60.html
我希望有人在将SO作为第一个搜索结果时发现这个有用;-)