[rules-users] ClassLoader Problem

Yann Massard y_massar at informatik.uni-kl.de
Thu Oct 16 13:32:51 EDT 2008


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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: DroolsTest.java
Type: text/x-java
Size: 2054 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/rules-users/attachments/20081016/b7aa643e/attachment.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Message.class
Type: application/java-vm
Size: 800 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/rules-users/attachments/20081016/b7aa643e/attachment-0001.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Message.java
Type: text/x-java
Size: 410 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/rules-users/attachments/20081016/b7aa643e/attachment-0002.bin 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Sample.drl
Url: http://lists.jboss.org/pipermail/rules-users/attachments/20081016/b7aa643e/attachment.pl 


More information about the rules-users mailing list