This issue was mentioned for moving from drooling from 3.06 to 4.0.7 , so which version of eclipse and drools are you using?
This may be due to the classpath problem:
Using the debugger, I realized that Drools PackageBuilder
tried to load classes from
Thread.currentThread().getContextClassLoader();
This ClassLoader
does not contain my agent classes! Even the system class loader does not contain my classes.
Decision:
Instead of creating simple instances of PackageBuilder
and RuleBase
you must create them using PackageBuilderConfiguration
and RuleBaseConfiguration
with the current ClassLoader
:
ClassLoader classLoader = this.getClass().getClassLoader(); PackageBuilderConfiguration configuration = new PackageBuilderConfiguration(); configuration.setClassLoader(classLoader); PackageBuilder builder = new PackageBuilder(configuration); builder.addPackageFromDrl(source); RuleBaseConfiguration ruleBaseConfiguration = new RuleBaseConfiguration(); ruleBaseConfiguration.setClassLoader(classLoader); ruleBase = RuleBaseFactory.newRuleBase(ruleBaseConfiguration); ruleBase.addPackage(builder.getPackage());
source share