[rules-users] ClassLoader Problem

John lists at johndubchak.com
Sat Oct 18 11:39:17 EDT 2008


Yann,

You need to add your com/sample/* classes to the classpath of your 
PluginClassLoader, or configure that ClassLoader to use a parent that 
has those classes on its classpath.

John

Yann Massard wrote:
> 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)? 
>



More information about the rules-users mailing list