未找到评估者定义的Drools类

时间:2015-02-06 15:11:33

标签: java drools

我正在使用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构造函数:( 有什么想法吗?

谢谢!

1 个答案:

答案 0 :(得分:1)

此类已从5.5.0.Final发布中消失。它出现在5.3.0和5.4.0(jar:drools-core.jar)中,大概也是早些时候。

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

如果您发布代码使用该类的方式,请使用s.o.可能想出办法来解决这个事故。

类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”。