我有一个我想在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();