Julien,
Thanks for reporting back!
Edson
2007/11/15, Julien Cassignol <julien.cassignol(a)imelios.com>:
Hello,
Following Mark's advice, I decided to mail about a problem I experienced
and managed to fix, with Mark's and Edson Tirelli's help.
I was trying to build a RuleBase with the following code :
final SpreadsheetCompiler converter = new
SpreadsheetCompiler();
FileInputStream file = new FileInputStream(decTable);
final String drl = converter.compile(file, InputType.XLS);
System.out.println(drl);
Properties properties = new Properties();
properties.setProperty( "drools.dialect.default",
"java" );
properties.setProperty("drools.compiler","JANINO");
PackageBuilderConfiguration conf = new
PackageBuilderConfiguration(properties);
PackageBuilder builder = new PackageBuilder( conf );
builder.addPackageFromDrl(new StringReader(drl));
Package pkg = builder.getPackage();
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage(pkg);
Nothing difficult, but it was failing on the construction of
PackageBuilderConfiguration :
No ClassLoaders found for:
org.drools.rule.builder.dialect.java.JavaDialect
Followed by an unhelpful stack.
Debugging my webapp (which sources I didn't have), I noticed that my
class ClassLoader was different from the thread one. The thread
classloader was the JBoss ClassLoader, and my class classloader was the
one of the webapp.
Setting the classloader of the thread manually to the classloader of my
webapp failed to cope with the problem, as the drools jars were
installed on Jboss, and drools instantiated object couldn't find core
objects within the classpath with the classloader of the webapp. To fix
the problem, I had to use the following code :
PackageBuilderConfiguration conf = new
PackageBuilderConfiguration(
properties);
conf.setClassLoader(MyClass.class.getClassLoader());
RuleBaseConfiguration ruleBaseConf = new
RuleBaseConfiguration();
ruleBaseConf.setClassLoader(MyClass.class.getClassLoader
());
Setting the classloader property of the drools configuration objects
allowed me to use imports of local classes (I mean local to the webapp)
within rule packages, and solved my problem (or so it seems).
I hope this short explanation will help someone !
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
--
Edson Tirelli
Software Engineer - JBoss Rules Core Developer
Office: +55 11 3529-6000
Mobile: +55 11 9287-5646
JBoss, a division of Red Hat @
www.jboss.com