Problems creating a Drools 4 project in Eclipse

I'm having trouble compiling a drools 4 project. I am getting errors in the rules file by saying

Only a type can be imported. <<MyClassName>> resolves to a package 

The incremental compiler does not work because of this. How to fix errors or make eclipse ignore them?

+2
source share
3 answers

Hmmm, I cleaned up the project and solved the problem.

-1
source

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()); 
+2
source

Make sure that MyClassName or any other classes (classes) that you use from the rule are in the jar file, and the jar file is in the class path.

+1
source

Source: https://habr.com/ru/post/1384808/


All Articles