[rules-users] Re: JUnit and classpath

J Michael Dean mdean77 at comcast.net
Sat Jan 5 13:00:15 EST 2008


Thanks.  I remain unable to use JUnit.  I have the code and several  
traces below and have attached them as files in case that is more  
readable.  The behavior, to summarize, is that if I add nothing to the  
JUnit classpath OR if I add the full org.drools.eclipse_4.0.3.jar to  
the classpath, I get an error instantiating the package builder, AFTER  
successfully instantiating a configuration.  If I use my own minimal  
drools plugin, I get an error instantiating the configuration itself.   
These lines are clearly marked in the code below, and the respective  
traces are below the code.

The minimal plugin works completely in my RCP, which uses essentially  
identical code to access Drools.  It includes

* drools-core - the rule engine itself.
		MVEL included just in case (because of the error I was  
misinterpreting)
* optional packages:
       o xpp3-1.1.3.4.O, xstream-1.2.2 - for audit feature

* drools-compiler - the rule compiler itself.
* antlr3-runtime-3.0
* eclipse-jdt-core-3.2.3.v_686_R32x -  to compile with eclipse

I don't really need JUnit to work against this minimal plugin, and I  
think when I add nothing to the JUnit classpath that JUnit already  
sees org.drools.eclipse_4.0.3.jar.


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: traces.txt
Url: http://lists.jboss.org/pipermail/rules-users/attachments/20080105/25a77796/attachment.txt 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: javaCode.java
Type: application/octet-stream
Size: 2512 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/rules-users/attachments/20080105/25a77796/attachment.obj 
-------------- next part --------------


In case the files are stripped, here are the contents.  Code followed  
by traces.

I appreciate Drools - it is terrific.  Thank you for any assistance  
you can provide to help me with this problem.

- Mike Dean


package droolsRules.tests;

import java.io.File;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.Reader;
import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.compiler.PackageBuilder;
import org.drools.compiler.PackageBuilderConfiguration;
import org.drools.rule.Package;
import org.drools.rule.builder.dialect.java.JavaDialectConfiguration;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

/**
  * This suite is the place to add Drools tests.
  *
  * @author J. Michael Dean, M.D., M.B.A. (University of Utah)
  * Copyright 2005 - 2008.  All Rights Reserved.
  *
  */

@RunWith(Suite.class)
@SuiteClasses( { TestHypoglycemiaDetection.class })
public class AllDroolsRulesTests {
	public static RuleBase ruleBase;

	@BeforeClass
	public static void setUp() throws Exception {
		Reader source;
		PackageBuilderConfiguration pkgConfig = new  
PackageBuilderConfiguration(); //ERROR OCCURS HERE WHEN I USE MY  
MINIMAL DROOLS PLUGIN JAR
		JavaDialectConfiguration javaDialectConf =  
(JavaDialectConfiguration) pkgConfig.getDialectConfiguration("java");
		javaDialectConf.setCompiler(JavaDialectConfiguration.ECLIPSE);
		
		if (pkgConfig == null) {
			System.out.println("Error - null package configuration");
		} else {
			System.out.println("Package configuration is not null");
		}
		final PackageBuilder builder = new PackageBuilder(pkgConfig); //  
ERROR OCCURS HERE WHEN I USE DROOLS.ORG.ECLIPSE_4.0.3.JAR
		boolean exists = (new File("rules/GlucoseDroolRules00.drl")).exists();
		if (exists) {
			builder.addPackageFromDrl(new FileReader(
				"rules/GlucoseDroolRules00.drl"));
			System.out.println("Found the file!");
		} else {
			System.out.println("Cannot locate the file - will try as resource");
			source = new InputStreamReader(AllDroolsRulesTests.class
					.getResourceAsStream("GlucoseDroolRules00.drl"));
			if (source == null){
				System.out.println("Could not get input stream");
			} else {
				System.out.println("Opened the stream successfully");
			}
			builder.addPackageFromDrl(source);
		}
		if (builder.hasErrors()) {
			System.out.println(builder.getErrors().toString());
		}
		Package pkg = builder.getPackage();
		ruleBase = RuleBaseFactory.newRuleBase();
		ruleBase.addPackage(pkg);
	}

	@AfterClass
	public static void tearDown() throws Exception {
	}

	public static RuleBase getRuleBase() {
		return ruleBase;
	}
}

Here are the respective traces (am sorry for the length of this post)

Here is the trace when I add nothing special to the JUnit classpath,  
showing that the configuration was instantiated in lines 38 - 40, but  
the crash occurs when instantiating the package builder in line 47.   
This crash occurs before any effort is made to load a DRL, etc.  I get  
the same identical trace if I add org.drools.eclipse_4.0.3.jar to the  
classpath, which makes sense to me because this jar is in my IDE  
environment and should be visible to JUnit.

Package configuration is not null
java.lang.NullPointerException
	at  
org.mvel.optimizers.OptimizerFactory.<clinit>(OptimizerFactory.java:43)
	at  
org.drools.rule.builder.dialect.mvel.MVELDialect.init(MVELDialect.java: 
142)
	at org.drools.compiler.DialectRegistry.initAll(DialectRegistry.java:49)
	at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:146)
	at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:108)
	at  
droolsRules.tests.AllDroolsRulesTests.setUp(AllDroolsRulesTests.java:47)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at  
sun 
.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java: 
39)
	at  
sun 
.reflect 
.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java: 
25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at  
org 
.junit 
.internal 
.runners.BeforeAndAfterRunner.invokeMethod(BeforeAndAfterRunner.java:74)
	at  
org 
.junit 
.internal 
.runners.BeforeAndAfterRunner.runBefores(BeforeAndAfterRunner.java:50)
	at  
org 
.junit 
.internal 
.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:33)
	at  
org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
	at  
org 
.eclipse 
.jdt 
.internal 
.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
	at  
org 
.eclipse 
.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at  
org 
.eclipse 
.jdt 
.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java: 
460)
	at  
org 
.eclipse 
.jdt 
.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java: 
673)
	at  
org 
.eclipse 
.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java: 
386)
	at  
org 
.eclipse 
.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java: 
196)
[MVEL] Notice: Possible incorrect version of ASM present (3.0  
required).  Disabling JIT compiler.  Reflective Optimizer will be used.

If, on the other hand, I add the plugin that I use in my RCP, "minimal  
Drools", I get a different trace.  My plugin includes
* drools-core - the rule engine itself.
		MVEL included just in case (because of the error I was  
misinterpreting)
* optional packages:
       o xpp3-1.1.3.4.O, xstream-1.2.2 - for audit feature

* drools-compiler - the rule compiler itself.
* antlr3-runtime-3.0
* eclipse-jdt-core-3.2.3.v_686_R32x -  to compile with eclipse

Now the trace shows that the configuration file is not instantiated:

org.drools.RuntimeDroolsException: Unable to load dialect  
'org.drools.rule.builder.dialect.java.JavaDialectConfiguration:java'
	at  
org 
.drools 
.compiler 
.PackageBuilderConfiguration 
.addDialect(PackageBuilderConfiguration.java:152)
	at  
org 
.drools 
.compiler 
.PackageBuilderConfiguration 
.buildDialectConfigurationMap(PackageBuilderConfiguration.java:140)
	at  
org 
.drools 
.compiler 
.PackageBuilderConfiguration.init(PackageBuilderConfiguration.java:117)
	at  
org 
.drools 
.compiler 
.PackageBuilderConfiguration.<init>(PackageBuilderConfiguration.java:94)
	at  
droolsRules.tests.AllDroolsRulesTests.setUp(AllDroolsRulesTests.java:38)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at  
sun 
.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java: 
39)
	at  
sun 
.reflect 
.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java: 
25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at  
org 
.junit 
.internal 
.runners.BeforeAndAfterRunner.invokeMethod(BeforeAndAfterRunner.java:74)
	at  
org 
.junit 
.internal 
.runners.BeforeAndAfterRunner.runBefores(BeforeAndAfterRunner.java:50)
	at  
org 
.junit 
.internal 
.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:33)
	at  
org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
	at  
org 
.eclipse 
.jdt 
.internal 
.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
	at  
org 
.eclipse 
.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at  
org 
.eclipse 
.jdt 
.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java: 
460)
	at  
org 
.eclipse 
.jdt 
.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java: 
673)
	at  
org 
.eclipse 
.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java: 
386)
	at  
org 
.eclipse 
.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java: 
196)
Caused by: java.lang.NullPointerException
	at  
org 
.drools 
.compiler 
.PackageBuilderConfiguration 
.addDialect(PackageBuilderConfiguration.java:146)
	... 18 more

On Jan 3, 2008, at 8:21 AM, rules-users-request at lists.jboss.org wrote:
>
>
> Message: 4
> Date: Thu, 03 Jan 2008 15:21:13 +0000
> From: Mark Proctor <mproctor at codehaus.org>
> Subject: Re: [rules-users] Re: JUnit and classpath
> To: Rules Users List <rules-users at lists.jboss.org>
> Message-ID: <477CFD69.4050301 at codehaus.org>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> J Michael Dean wrote:
>> I noticed the absence of asm and tried to manually add version 3.1  
>> and
>> this had no effect on the trace.
> It gets  a null pointer and says it can't use ASM in MVEL, thus uses
> reflection mode. That's fine as reflection is the mode we put MVEL in
> anyway. It's more of am informational warning than an error.
>>
>> ...
>>
>> On Jan 2, 2008, at 10:00 AM, rules-users-request at lists.jboss.org  
>> wrote:
>>
>>>
>>>
>>> Mike,
>>>
>>> So it seems you are missing the ASM jar in your classpath... did you
>>> tried
>>> adding it?
>>> BTW, what is this MinimalDroolCore_1.0.0.jar that you are adding to
>>> your
>>> classpath? Drools also includes an inlined ASM version inside it for
>>> its own
>>> use... are you stripping that?
>>>
>>> []s
>>> Edson
>>>
>>>>>> ...
>>>>>> Mike,
>>>>>>
>>>>>> This looks like a classpath problem indeed. Did you tried asking
>>>>>> the JVM
>>>>>> to dump its classpath so that you can know for sure what jars are
>>>>>> included
>>>>>> and if any of them embeds a non-compatible ASM version ?
>>>>>>
>>>>>> []s
>>>>>> Edson
>>>>>>
>>>>>>
>>>>>> _______________________________________________
>>>>>> rules-users mailing list
>>>>>> rules-users at lists.jboss.org
>>>>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>>>>
>>>>>>
>>>>>
>>>>>


More information about the rules-users mailing list