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

Julien Cassignol julien.cassignol at imelios.com
Thu Nov 15 09:51:05 EST 2007


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 !



More information about the rules-users mailing list