Problems building Drools 4 project in Eclipse
Question
I'm having trouble compiling a drools 4 project. I'm getting errors in the rules file saying
Only a type can be imported. <<MyClassName>> resolves to a package
The incremental compiler isn't working because of this. How do I fix the errors or get eclipse to ignore them?
Solution 3
Hmmm, I cleaned the project and that resolved the problem.
OTHER TIPS
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
andRuleBase
instances, one has to create them with aPackageBuilderConfiguration
and aRuleBaseConfiguration
both with the currentclassLoader
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());
Ensure that the MyClassName or any other class(es) that you use from the rule are in a jar file and the jar file is in classpath.