Hi,
I am using version 4.0.7 of Drools.
I am trying to load facts with a particular ClassLoader and compiling
the rules using the same ClassLoader:
------
Reader source = new FileReader("plugin/Sample.drl");
ClassLoader pluginClassLoader = new PluginClassLoader();
Thread.currentThread().setContextClassLoader( pluginClassLoader );
PackageBuilder builder = new PackageBuilder(new
PackageBuilderConfiguration(pluginClassLoader));
builder.addPackageFromDrl(source);
Package pkg = builder.getPackage();
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage(pkg);
------
This works fine for usage of the fact types in the LHS of rules and for
field extraction.
But when I add a method invocation or an update statement on a fact to
the RHS of a rule I get a rule compilation error:
-------
org.drools.rule.InvalidRulePackage: Rule Compilation error : [Rule
name=Hello World, agendaGroup=MAIN, salience=0, no-loop=false]
com/sample/Rule_Hello_World_0.java (6:267) : plugin.Message cannot be
resolved to a type
-------
I have reduced the problem to a minimal complexity (see attachments).
Any ideas?
By the way: do I really need to set both the ClassLoader in the
PackageBuilderConfiguration AND the ContextClassLoader (as described in
http://blog.athico.com/2006/12/dynamically-generated-class-beans-as.html)?
Thanks in advance!
Best regards
Yann Massard
package com.sample
import plugin.*; // change to plugin.Message and it won't work!
rule "Hello World"
when
m : Message( status == Message.HELLO, message : message )
then
System.out.println( message );
// NONE OF THE FOLLOWING WORKS:
m.setMessage( "Goodbye cruel world" );
m.setStatus( Message.GOODBYE );
update( m );
end
rule "GoodBye"
no-loop true
when
m : Message( status == Message.GOODBYE, message : message )
then
System.out.println( message );
// NONE OF THE FOLLOWING WORKS:
m.setMessage( message );
end