gpt4 book ai didi

java - 未找到用于评估器定义的 Drools 类

转载 作者:行者123 更新时间:2023-12-01 11:57:09 25 4
gpt4 key购买 nike

我正在使用 Drools 5.5.0-Final,突然出现这个异常

我将所有库再次放入我的项目中,但结果是相同的

org.drools.RuntimeDroolsException: Class not found for evaluator definition: org.drools.base.evaluators.EqualityEvaluatorsDefinition
at org.drools.base.evaluators.EvaluatorRegistry.addEvaluatorDefinition(EvaluatorRegistry.java:136)
at org.drools.compiler.PackageBuilderConfiguration.buildEvaluatorRegistry(PackageBuilderConfiguration.java:550)
at org.drools.compiler.PackageBuilderConfiguration.init(PackageBuilderConfiguration.java:196)
at org.drools.compiler.PackageBuilderConfiguration.<init>(PackageBuilderConfiguration.java:170)
at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:300)
at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:228)
at org.drools.builder.impl.KnowledgeBuilderFactoryServiceImpl.newKnowledgeBuilder(KnowledgeBuilderFactoryServiceImpl.java:34)
at org.drools.builder.KnowledgeBuilderFactory.newKnowledgeBuilder(KnowledgeBuilderFactory.java:46)
at com.drools.optimizer.AppExpertSystem.readKnowledgeBase(AppExpertSystem.java:130)
at com.drools.optimizer.AppExpertSystem.loadKnowledgeBase(AppExpertSystem.java:115)
at com.drools.optimizer.AppExpertSystem.<init>(AppExpertSystem.java:46)
at eventlauncher.OptimizerLauncher.NuevoEscenario(OptimizerLauncher.java:57)
at eventlauncher.DemoPruebas.main(DemoPruebas.java:18)
Caused by: java.lang.ClassNotFoundException: Unable to load class: org.drools.base.evaluators.EqualityEvaluatorsDefinition
at org.drools.util.CompositeClassLoader.loadClass(CompositeClassLoader.java:92)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at org.drools.base.evaluators.EvaluatorRegistry.addEvaluatorDefinition(EvaluatorRegistry.java:132)
... 12 more
Exception in thread "main" java.lang.RuntimeException: org.drools.RuntimeDroolsException: Class not found for evaluator definition: org.drools.base.evaluators.EqualityEvaluatorsDefinition
at com.drools.optimizer.AppExpertSystem.loadKnowledgeBase(AppExpertSystem.java:122)
at com.drools.optimizer.AppExpertSystem.<init>(AppExpertSystem.java:46)
at eventlauncher.OptimizerLauncher.NuevoEscenario(OptimizerLauncher.java:57)
at eventlauncher.DemoPruebas.main(DemoPruebas.java:18)
Caused by: org.drools.RuntimeDroolsException: Class not found for evaluator definition: org.drools.base.evaluators.EqualityEvaluatorsDefinition
at org.drools.base.evaluators.EvaluatorRegistry.addEvaluatorDefinition(EvaluatorRegistry.java:136)
at org.drools.compiler.PackageBuilderConfiguration.buildEvaluatorRegistry(PackageBuilderConfiguration.java:550)
at org.drools.compiler.PackageBuilderConfiguration.init(PackageBuilderConfiguration.java:196)
at org.drools.compiler.PackageBuilderConfiguration.<init>(PackageBuilderConfiguration.java:170)
at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:300)
at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:228)
at org.drools.builder.impl.KnowledgeBuilderFactoryServiceImpl.newKnowledgeBuilder(KnowledgeBuilderFaorg.drools.RuntimeDroolsException: Class not found for evaluator definition: org.drools.base.evaluators.EqualityEvaluatorsDefinition
at org.drools.base.evaluators.EvaluatorRegistry.addEvaluatorDefinition(EvaluatorRegistry.java:136)
at org.drools.compiler.PackageBuilderConfiguration.buildEvaluatorRegistry(PackageBuilderConfiguration.java:550)
at org.drools.compiler.PackageBuilderConfiguration.init(PackageBuilderConfiguration.java:196)
at org.drools.compiler.PackageBuilderConfiguration.<init>(PackageBuilderConfiguration.java:170)
at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:300)
at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:228)
at org.drools.builder.impl.KnowledgeBuilderFactoryServiceImpl.newKnowledgeBuilder(KnowledgeBuilderFactoryServiceImpl.java:34)
at org.drools.builder.KnowledgeBuilderFactory.newKnowledgeBuilder(KnowledgeBuilderFactory.java:46)
at com.drools.optimizer.AppExpertSystem.readKnowledgeBase(AppExpertSystem.java:130)
at com.drools.optimizer.AppExpertSystem.loadKnowledgeBase(AppExpertSystem.java:115)
at com.drools.optimizer.AppExpertSystem.<init>(AppExpertSystem.java:46)
at eventlauncher.OptimizerLauncher.NuevoEscenario(OptimizerLauncher.java:57)
at eventlauncher.DemoPruebas.main(DemoPruebas.java:18)
Caused by: java.lang.ClassNotFoundException: Unable to load class: org.drools.base.evaluators.EqualityEvaluatorsDefinition
at org.drools.util.CompositeClassLoader.loadClass(CompositeClassLoader.java:92)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at org.drools.base.evaluators.EvaluatorRegistry.addEvaluatorDefinition(EvaluatorRegistry.java:132)
... 12 more
Exception in thread "main" java.lang.RuntimeException: org.drools.RuntimeDroolsException: Class not found for evaluator definition: org.drools.base.evaluators.EqualityEvaluatorsDefinition
at com.drools.optimizer.AppExpertSystem.loadKnowledgeBase(AppExpertSystem.java:122)
at com.drools.optimizer.AppExpertSystem.<init>(AppExpertSystem.java:46)
at eventlauncher.OptimizerLauncher.NuevoEscenario(OptimizerLauncher.java:57)
at eventlauncher.DemoPruebas.main(DemoPruebas.java:18)
Caused by: org.drools.RuntimeDroolsException: Class not found for evaluator definition: org.drools.base.evaluators.EqualityEvaluatorsDefinition
at org.drools.base.evaluators.EvaluatorRegistry.addEvaluatorDefinition(EvaluatorRegistry.java:136)
at org.drools.compiler.PackageBuilderConfiguration.buildEvaluatorRegistry(PackageBuilderConfiguration.java:550)
at org.drools.compiler.PackageBuilderConfiguration.init(PackageBuilderConfiguration.java:196)
at org.drools.compiler.PackageBuilderConfiguration.<init>(PackageBuilderConfiguration.java:170)
at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:300)
at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:228)
at org.drools.builder.impl.KnowledgeBuilderFactoryServiceImpl.newKnowledgeBuilder(KnowledgeBuilderFactoryServiceImpl.java:34)
at org.drools.builder.KnowledgeBuilderFactory.newKnowledgeBuilder(KnowledgeBuilderFactory.java:46)
at com.drools.optimizer.AppExpertSystem.readKnowledgeBase(AppExpertSystem.java:130)
at com.drools.optimizer.AppExpertSystem.loadKnowledgeBase(AppExpertSystem.java:115)
... 3 more
Caused by: java.lang.ClassNotFoundException: Unable to load class: org.drools.base.evaluators.EqualityEvaluatorsDefinition
at org.drools.util.CompositeClassLoader.loadClass(CompositeClassLoader.java:92)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at org.drools.base.evaluators.EvaluatorRegistry.addEvaluatorDefinition(EvaluatorRegistry.java:132)
... 12 morectoryServiceImpl.java:34)
at org.drools.builder.KnowledgeBuilderFactory.newKnowledgeBuilder(KnowledgeBuilderFactory.java:46)
at com.drools.optimizer.AppExpertSystem.readKnowledgeBase(AppExpertSystem.java:130)
at com.drools.optimizer.AppExpertSystem.loadKnowledgeBase(AppExpertSystem.java:115)
... 3 more
Caused by: java.lang.ClassNotFoundException: Unable to load class: org.drools.base.evaluators.EqualityEvaluatorsDefinition
at org.drools.util.CompositeClassLoader.loadClass(CompositeClassLoader.java:92)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at org.drools.base.evaluators.EvaluatorRegistry.addEvaluatorDefinition(EvaluatorRegistry.java:132)
... 12 more

我的代码是:

import com.answare.backendconnection.RESTConnection;
import com.answare.dataModel.ActionANS;
import com.answare.dataModel.CrisisContextANS;
import com.answare.db.QueriesDB;
import com.answare.settings.CTES;
import com.drools.utils.Event;
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseConfiguration;
import org.drools.KnowledgeBaseFactory;
import org.drools.builder.*;
import org.drools.conf.EventProcessingOption;
import org.drools.io.ResourceFactory;
import org.drools.runtime.StatefulKnowledgeSession;
import java.sql.SQLException;



/**
* This is the class that launch Expert System.
*/

public class AppExpertSystem {

StatefulKnowledgeSession ksession;
DSS_ANS optimizerDSS_ANS;
Event event;
RESTConnection restConnection;


public AppExpertSystem() {
loadKnowledgeBase();
optimizerDSS_ANS = new DSS_ANS(ksession);
event = new Event();
event.setNewEvent(true);
}
public AppExpertSystem(RESTConnection restConnection){
loadKnowledgeBase();
event = new Event();
event.setNewEvent(true);
this.restConnection = restConnection;
}



private void loadKnowledgeBase() {
// load up the knowledge base
KnowledgeBase kbase;
try {
kbase = readKnowledgeBase();
ksession = kbase.newStatefulKnowledgeSession();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}


private static KnowledgeBase readKnowledgeBase() throws Exception {

KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource(CTES.RULES),
ResourceType.DRL);
KnowledgeBuilderErrors errors = kbuilder.getErrors();

if (errors.size() > 0) {
for (KnowledgeBuilderError error : errors) {
System.err.println(error);
}
throw new IllegalArgumentException("Could not parse knowledge.");
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
KnowledgeBaseConfiguration config = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
config.setOption(EventProcessingOption.STREAM );

return kbase;
}


public String executeMessage(CrisisContextANS crisisContext) {
try {
storeInDatabaseCrisis(crisisContext,true);
ksession.setGlobal("optimizerDSS", optimizerDSS_ANS);
ksession.insert(crisisContext);
this.event.setType("CrisisContextANS");
ksession.insert(this.event);
int num = ksession.fireAllRules();
if (num != 0) {
this.event.setNewEvent(false);
return ("Run OK from Expert System");
}
return ("");
} catch (Throwable t) {
t.printStackTrace();
return ("Run NOT OK Expert System");
}
}
}

异常发生在方法 readKnowledgeBase() 中,位于

KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

我正在做的唯一一件事就是调用 AppExpertSystem 构造函数:(有什么想法吗?

谢谢!

最佳答案

此类已从 5.5.0.Final 发行版中消失。它存在于 5.3.0 和 5.4.0(jar:drools-core.jar)中,大概也更早。

org.drools.base 和 ...evaluators 不是 5.3 和 5.4 中稳定 API 的一部分,因此使用它是有风险的。

如果您发布代码如何使用该类,那么可能会想出一种方法来解决这个事故。

类 org.drools.base.evaluators.EqualityEvaluatorsDefinition 通常通过包含一行来配置到构建器中

drools.evaluator.equality = org.drools.base.evaluators.EqualityEvaluatorsDefinition

在工作目录、主目录或某些 jar 的 META-INF drools.default.packagebuilder.conf 中的文件“drools.packagebuilder.conf”中,或者在系统属性“drools.packagebuilder”指向的文件中.conf”。

关于java - 未找到用于评估器定义的 Drools 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28368797/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com