[rules-users] Classloader issues with webapp : No ClassLoaders found, Circular dependencies...

2007-11-15 Thread Julien Cassignol
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@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Classloader issues with webapp : No ClassLoaders found, Circular dependencies...

2007-11-15 Thread Robert Morse

Very helpful to me!  Thank you Julien!

On Nov 15, 2007, at 8:48 AM, Edson Tirelli wrote:



   Julien,

   Thanks for reporting back!

   Edson

2007/11/15, Julien Cassignol [EMAIL PROTECTED]:

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Classloader issues with webapp : No ClassLoaders found, Circular dependencies...

2007-11-15 Thread Edson Tirelli
   Julien,

   Thanks for reporting back!

   Edson

2007/11/15, Julien Cassignol [EMAIL PROTECTED]:

 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@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
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users