Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用自定义类装入器Drools 6_Java_Classloader_Drools_Drools Guvnor - Fatal编程技术网

Java 使用自定义类装入器Drools 6

Java 使用自定义类装入器Drools 6,java,classloader,drools,drools-guvnor,Java,Classloader,Drools,Drools Guvnor,我想在Drools 6.0.1决策表中使用一个类,它不在默认类装入器中。我创建了一个自定义类加载器,我想在Drools中使用它,但我只能找到KieBaseConfiguration类来设置它。这似乎对返回“找不到类”错误的KieBuilder没有影响。如何设置生成器的类装入器 代码如下: // Create the classloader and make sure the class is available. ClassLoader loader = getClassLoader(); Cl

我想在Drools 6.0.1决策表中使用一个类,它不在默认类装入器中。我创建了一个自定义类加载器,我想在Drools中使用它,但我只能找到KieBaseConfiguration类来设置它。这似乎对返回“找不到类”错误的KieBuilder没有影响。如何设置生成器的类装入器

代码如下:

// Create the classloader and make sure the class is available.
ClassLoader loader = getClassLoader();
Class<?> clazz = loader.loadClass("actions.TestAction");

// Create the model
KieServices kieServices = KieServices.Factory.get();
KieModuleModel kieModuleModel = kieServices.newKieModuleModel();
KieBaseModel kieBaseModel1 = kieModuleModel.newKieBaseModel( "KBase1")
    .setDefault( true )
    .setEqualsBehavior( EqualityBehaviorOption.EQUALITY )
    .setEventProcessingMode( EventProcessingOption.STREAM );
KieSessionModel model = kieBaseModel1.newKieSessionModel( "KSession1" )
    .setDefault( true )
    .setType( KieSessionModel.KieSessionType.STATELESS )
    .setClockType( ClockTypeOption.get("realtime") );

// Create a new configuration with the new classloader. Does not seem to 
// do anything with regard to rule compilation.
KieBaseConfiguration kbaseConf = 
                kieServices.newKieBaseConfiguration( null, loader );

// Create a file system and load the rule.
KieFileSystem kfs = kieServices.newKieFileSystem();
String decisionTable = 
    ",RuleSet,\n"+
    ",Import,conditions.test.TestCondition\n"+
    ",Sequential,TRUE\n"+
    ",,\n"+
    ",RuleTable System Table,\n"+
    ",CONDITION,ACTION\n"+
    ",TestCondition,testAction\n"+
    ",conditionID,test(\"$param\")\n"+
    "Case,Table,Log\n"+
    "Test,10027,Random Text\n"+
    ",,\n"+
    ",,\n"+
    ",Variables,actions.TestAction testAction\n";
kfs = kfs.write("src/main/resources/KBase1.csv", decisionTable);

// Build the rules. I get a compilation error here, actions.TestAction class 
// not found.
KieBuilder kieBuilder = kieServices.newKieBuilder(kfs).buildAll();
//创建类加载器并确保该类可用。
ClassLoader=getClassLoader();
Class clazz=loader.loadClass(“actions.TestAction”);
//创建模型
KieServices=KieServices.Factory.get();
KieModuleModel KieModuleModel=kieServices.newKieModuleModel();
KieBaseModel kieBaseModel1=kieModuleModel.newKieBaseModel(“KBase1”)
.setDefault(真)
.setEqualsBehavior(equalityBehavior选项.EQUALITY)
.setEventProcessingMode(EventProcessingOption.STREAM);
KieSessionModel=kieBaseModel1.newKieSessionModel(“KSession1”)
.setDefault(真)
.setType(KieSessionModel.KieSessionType.STATELESS)
.setClockType(ClockTypeOption.get(“实时”));
//使用新的类加载器创建新配置。似乎没有
//做任何关于规则汇编的事情。
KieBaseConfiguration kbaseConf=
newKieBaseConfiguration(null,loader);
//创建文件系统并加载规则。
KieFileSystem kfs=kieServices.newKieFileSystem();
字符串决策表=
,规则集,\n+
,导入,条件。测试。测试条件\n+
,顺序,为真\n+
“,\n”+
,规则表系统表,\n+
,条件,操作\n+
,TestCondition,testAction\n+
,条件ID,测试(\“$param\”)\n+
案例、表格、日志\n+
测试,10027,随机文本\n+
“,\n”+
“,\n”+
“,变量,操作。测试操作\n”;
kfs=kfs.write(“src/main/resources/KBase1.csv”,decisionTable);
//建立规则。我在这里得到一个编译错误,actions.TestAction类
//没有找到。
KieBuilder KieBuilder=kieServices.newKieBuilder(kfs.buildAll();

您能找到解决方案吗?或者是一个工作环境?如果有,请把它寄出去好吗?我面临着同样的问题;不同的是,我使用的是版本“6.1.0 Final”,其中方法
newKieBaseConfiguration(Properties,ClassLoader)
被标记为弃用,表示传递到此处的类加载器将被忽略,但在您的版本-6.0.1 Final中,没有指出这一点。任何人都找到了解决方案。我面临同样的问题