Java 8, Drools 5.x and Drools 7.x

蹲街弑〆低调 提交于 2019-12-24 23:15:12

问题


I am using Drools 5.x (drools-compiler 5.2.1.Final, drools-decisiontables 5.4.0.Final, and drools-templates 5.4.0.Final; jbpm-flow 5.1.1.Final, jbpm-bmpn2 5.1.1.Final and with their respective dependencies) for my Java job, I build/run it with Java 1.7.0_21. My current set up works properly. I am using a decision table (spreadsheet).

I am able to build/run my project with Java 1.8.0_162 using drools 5.x as described above; however, when the java job runs it loads the decision table (spreadsheet) but it does not fire up any of the rules, I am not getting an exception in the last line that gets executed:

Properties props = new Properties();

KnowledgeBuilderConfiguration configuration = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(props);

KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newDecisionTableConfiguration(configuration);

DecisionTableConfiguration config = KnowledgeBuilderFactory.newDecisionTableConfiguration();

config.setInputType(DecisionTableInputType.XLS);

kbuilder.add(ResourceFactory.newClassPathResource(spreadsheetFile), ResourcType.DTABLE, config);  // last line executed and then job exists and completes successfully.

Prior to the last line getting executed I put some debug logs and they show the following:

Properties (props): {}

KnowledgeBuilderConfiguration (configuration): org.drools.compiler.PackageBuilderConfiguration@630cb4a4

KnowledgeBuilder (kbuilder): org.drools.builder.impl.KnowledgeBuilderImpl@239bof9d

ResourceFactory.newClassPathResource(spreadsheetFile): [ClassPathResource path='spreadsheet.xls']

ResourceType.DTABLE: ResourceType = 'Decision Table'

DecisionTableConfiguration (config): org.drools.builder.conf.impl.DecisionTableConfigurationImpl@150ab4ed

DecisionTableConfiguration (config.getInputType()): XLS

So I decided to upgrade from drools 5.5.0 to 7.5.0 and use kie-api/kie-ci; I had to do some refactoring because now drools is part of the KIE (Knowledge Is Everything) umbrella, see the code below:

KieServices ks = KieServices.Factory.get();
KieContainer kc = ks.getKieClasspathContainer();
KieSession ks = kc.newKieSession("ksession-dtables");  //stateful session
FactHandle fh = ks.insert(fact);
ks.fireAllRules();

....

The packages and rules are loaded into the Knowledge Base but only the first rules fire up and then it stops, do I need to upgrade my decision table (spreadsheet) in order to work for drools 7.5.0 with Java 8?

Any suggestions are welcome.

Thanks!!


回答1:


I started using drools 6.5.0 and everything works now.



来源:https://stackoverflow.com/questions/50511357/java-8-drools-5-x-and-drools-7-x

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!