I have a class I would like to use in a Drools 6.0.1 decision table that is not in the default class loader. I created a custom class loader that I would like to use in Drools but I can only find the KieBaseConfiguration class to set it. This does not seem to have an effect on the KieBuilder which is returning an "Unable to find Class" error. How do I set the class loader for the builder?
Code is below:
// 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();