Java 8 如何在drools 6.3.0中以编程方式切换到ReteOO算法?

Java 8 如何在drools 6.3.0中以编程方式切换到ReteOO算法?,java-8,drools,Java 8,Drools,我正在从事一个涉及Java8和Drools6.3.0的项目。早些时候,我曾使用Java7和Drools 5.4.0。我了解到Drools 6.0.0之后,PHREAK被设置为默认算法。在谷歌搜索这个问题时,我遇到了一些解决方案,建议传递参数-Ddrools.ruleEngine=reteoo来明确设置它。当我做同样的事情时,我遇到了以下错误 java.lang.NoClassDefFoundError: Could not initialize class cmn.rules.canonical

我正在从事一个涉及Java8和Drools6.3.0的项目。早些时候,我曾使用Java7和Drools 5.4.0。我了解到Drools 6.0.0之后,PHREAK被设置为默认算法。在谷歌搜索这个问题时,我遇到了一些解决方案,建议传递参数-Ddrools.ruleEngine=reteoo来明确设置它。当我做同样的事情时,我遇到了以下错误

java.lang.NoClassDefFoundError: Could not initialize class cmn.rules.canonical.CanRuleEngineFactory$CanRuleEngineFactoryWrapper
at cmn.rules.canonical.CanRuleEngineFactory.getInstance(CanRuleEngineFactory.java:33)
at cmn.service.impl.SecurityPersistanceServiceImpl.applyLoaderRules(SecurityPersistanceServiceImpl.java:69)
at cmn.service.impl.SecurityPersistanceServiceImpl.load(SecurityPersistanceServiceImpl.java:216)
at udl.persistence.LoaderDelegatorImpl.load(LoaderDelegatorImpl.java:255)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy63.load(Unknown Source)
at udl.core.task.LoaderTask.executeTask(LoaderTask.java:139)
at cmn.core.concurrent.WorkerThread.runTask(WorkerThread.java:94)
at cmn.core.concurrent.WorkerThread.run(WorkerThread.java:74)
at java.lang.Thread.run(Thread.java:745)
但是,当我传递参数-Ddrools.ruleEngine=phreak时,代码不会出现任何问题

另一个建议是:, 我的代码是这样的

private static KnowledgeBaseConfiguration kBaseConf;
kBaseConf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
kBaseConf.setProperty("drools.ruleEngine", "reteoo");
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kBaseConf);
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
return kbase;
这导致了以下错误:

java.lang.NullPointerException
    at org.drools.impl.KnowledgeBaseFactoryServiceImpl.newKnowledgeBase(KnowledgeBaseFactoryServiceImpl.java:75)
    at org.drools.KnowledgeBaseFactory.newKnowledgeBase(KnowledgeBaseFactory.java:88)
    at RuleEngineFactory.readKnowledgeBase(RuleEngineFactory.java:139)
    at RuleEngineFactory.createRuleFromResource(RuleEngineFactory.java:104)
    at RuleEngineFactory.<init>(RuleEngineFactory.java:79)
    at canonical.AbstractCanonicalRuleEngineFactory.<init>(AbstractCanonicalRuleEngineFactory.java:40)
    at canonical.CanRuleEngineFactory.<init>(CanRuleEngineFactory.java:31)
    at canonical.CanRuleEngineFactory.getInstance(CanRuleEngineFactory.java:38)
    at PersistanceServiceImpl.applyLoaderRules(SecurityPersistanceServiceImpl.java:69)
    at PersistanceServiceImpl.load(SecurityPersistanceServiceImpl.java:218)
    at com.dclear.udl.persistence.LoaderDelegatorImpl.load(LoaderDelegatorImpl.java:255)
    at sun.reflect.GeneratedMethodAccessor166.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
    at com.sun.proxy.$Proxy63.load(Unknown Source)
java.lang.NullPointerException
位于org.drools.impl.KnowledgeBaseFactoryServiceImpl.newKnowledgeBase(KnowledgeBaseFactoryServiceImpl.java:75)
位于org.drools.KnowledgeBaseFactory.newKnowledgeBase(KnowledgeBaseFactory.java:88)
位于RuleEngineFactory.readKnowledgeBase(RuleEngineFactory.java:139)
位于RuleEngineFactory.createRuleFromResource(RuleEngineFactory.java:104)
在RuleEngineFactory。(RuleEngineFactory.java:79)
位于canonical.AbstractCanonicalRuleEngineFactory。(AbstractCanonicalRuleEngineFactory.java:40)
在canonical.CanRuleEngineFactory上。(CanRuleEngineFactory.java:31)
位于canonical.CanRuleEngineFactory.getInstance(CanRuleEngineFactory.java:38)
在PersistanceServiceImpl.applyLoaderRules(SecurityPersistanceServiceImpl.java:69)上
在PersistanceServiceImpl.load(SecurityPersistanceServiceImpl.java:218)处
位于com.dclear.udl.persistence.LoaderDelegatorImpl.load(LoaderDelegatorImpl.java:255)
位于sun.reflect.GeneratedMethodAccessor166.invoke(未知源)
在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)中
位于java.lang.reflect.Method.invoke(Method.java:497)
位于org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302)
位于org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
在org.springframework.aop.framework.ReflectiveMethodInvocation.procedue(ReflectiveMethodInvocation.java:157)上
位于org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
位于org.springframework.transaction.interceptor.TransactionSpectSupport.invokeWithinTransaction(TransactionSpectSupport.java:281)
位于org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
在org.springframework.aop.framework.ReflectiveMethodInvocation.procedue(ReflectiveMethodInvocation.java:179)上
位于org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
位于com.sun.proxy.$Proxy63.load(未知源)
如果有人能为这个问题提供一个解决方案或至少一些指针,我将不胜感激

提前感谢,

您可以使用程序包org.kie.internal.builder.conf中的KieBaseConfiguration和非稳定(!)RuleEngineOption“成功”设置KieBase配置选项

KieServices ks = KieServices.Factory.get();
KieBaseConfiguration kbConf = ks.newKieBaseConfiguration();
kbConf.setOption( RuleEngineOption.RETEOO );
KieBase kieBase = kieContainer.newKieBase( kbConf );
也可以在命令行上使用-Ddrools.ruleEngine=reteoo生成用于启动Java应用程序的设置

您可以使用验证选项设置是否成功

System.out.println( kbConf.getProperty( "drools.ruleEngine" ) );
在“成功”设置之后以及执行时

KieBase kieBase = kieContainer.newKieBase( kbConf );
程序运行,但会通知您

[main] WARN org.drools.core.RuleBaseConfiguration - 
       Cannot find drools-reteoo.jar on the classpath, 
       switching to phreak
但是6.2.0发行版中没有包含这个jar。我认为这个切换只是在6.0.0开发过程中切换回来的一个临时黑客

继续使用5.4.0(或5.5.0或更高版本)并使用Java8——应该不会有问题。或者继续使用PHREAK-应该更好。

您可以使用org.kie.internal.builder.conf包中的KieBaseConfiguration和非稳定(!)RuleEngineOption“成功”设置KieBase配置选项

KieServices ks = KieServices.Factory.get();
KieBaseConfiguration kbConf = ks.newKieBaseConfiguration();
kbConf.setOption( RuleEngineOption.RETEOO );
KieBase kieBase = kieContainer.newKieBase( kbConf );
也可以在命令行上使用-Ddrools.ruleEngine=reteoo生成用于启动Java应用程序的设置

您可以使用验证选项设置是否成功

System.out.println( kbConf.getProperty( "drools.ruleEngine" ) );
在“成功”设置之后以及执行时

KieBase kieBase = kieContainer.newKieBase( kbConf );
程序运行,但会通知您

[main] WARN org.drools.core.RuleBaseConfiguration - 
       Cannot find drools-reteoo.jar on the classpath, 
       switching to phreak
但是6.2.0发行版中没有包含这个jar。我认为这个切换只是在6.0.0开发过程中切换回来的一个临时黑客


继续使用5.4.0(或5.5.0或更高版本)并使用Java8——应该不会有问题。或者继续使用PHREAK-它应该更好。

我们使用的是知识API而不是Kie API。您能否使用Knowledge API提供相同的解决方案?您是否有关于-Ddrools.ruleEngine=reteoo的任何信息?Knowledge API在6.x中已被弃用。但是您可以在javadoc中查找这些调用。从6.3开始,drools-reteoo现在再次成为发行版的一部分。它总是在nexus发行版上,我们使用的是知识API而不是Kie API。您能否使用Knowledge API提供相同的解决方案?您是否有关于-Ddrools.ruleEngine=reteoo的任何信息?Knowledge API在6.x中已被弃用。但是您可以在javadoc中查找这些调用。从6.3开始,drools-reteoo现在再次成为发行版的一部分。它总是在nexus发行版上。