This issue was mentioned for a migration from drools 3.06 to 4.0.7, so what version of eclipse and drools are you using?
This might be related to a classpath issue:
Using the debugger I realized that the Drools PackageBuilder
tried to load the classes from the
Thread.currentThread().getContextClassLoader();
This ClassLoader
does not contain my agent classes! Even the system class loader does not contain my classes.
The solution was:
Instead of creating plain PackageBuilder
and RuleBase
instances, one has to create them with a PackageBuilderConfiguration
and a RuleBaseConfiguration
both with the current classLoader
configured:
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());