Hi,

 

I am running into a strange classloader issue when running test cases in Ant.  Outside of Ant, the test cases and application itself just run fine.  It’s only when I attempt to run the test case from within Ant that I get the error below:

 

Drools 5.0.1

Ant 1.6

JUnit 4.7

 

  <testcase classname="com.siemens.pl.it.gre.rules.TestJUnit" name="testRule" time="1.75">

    <error message="TestObject (wrong name: com/siemens/pl/it/gre/rules/TestObject)" type="java.lang.NoClassDefFoundError">java.lang.NoClassDefFoundError: TestObject (wrong name: com/siemens/pl/it/gre/rules/TestObject)

      at java.lang.ClassLoader.defineClass1(Native Method)

      at java.lang.ClassLoader.defineClass(ClassLoader.java:620)

      at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)

      at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)

      at java.net.URLClassLoader.access$100(URLClassLoader.java:56)

      at java.net.URLClassLoader$1.run(URLClassLoader.java:195)

      at java.security.AccessController.doPrivileged(Native Method)

      at java.net.URLClassLoader.findClass(URLClassLoader.java:188)

      at java.lang.ClassLoader.loadClass(ClassLoader.java:306)

      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)

      at java.lang.ClassLoader.loadClass(ClassLoader.java:251)

      at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

      at java.lang.Class.forName0(Native Method)

      at java.lang.Class.forName(Class.java:242)

      at org.drools.rule.CompositeClassLoader.loadClass(CompositeClassLoader.java:61)

      at java.lang.ClassLoader.loadClass(ClassLoader.java:251)

      at org.drools.base.ClassTypeResolver.resolveType(ClassTypeResolver.java:144)

      at org.drools.rule.builder.PatternBuilder.build(PatternBuilder.java:140)

      at org.drools.rule.builder.PatternBuilder.build(PatternBuilder.java:104)

      at org.drools.rule.builder.GroupElementBuilder.build(GroupElementBuilder.java:69)

      at org.drools.rule.builder.RuleBuilder.build(RuleBuilder.java:68)

      at org.drools.compiler.PackageBuilder.addRule(PackageBuilder.java:1159)

      at org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:649)

      at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:290)

      at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:488)

      at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:25)

      at com.siemens.pl.it.gre.rules.AbstractRulesTestCase.createRuleBase(AbstractRulesTestCase.java:62)

      at com.siemens.pl.it.gre.rules.TestJUnit.setUp(TestJUnit.java:21)

</error>

 

 

Ant snippet:

      <target name="unitTest2">

            <junit fork="yes">

                  <classpath>

                        <path refid="classpath" />

                  </classpath>

 

                  <formatter type="xml" />

                  <test name="com.siemens.pl.it.gre.rules.TestJUnit" haltonfailure="yes" outfile="${test.reports.dir}/results">

                        <formatter type="xml" />

                  </test>

            </junit>

      </target>

 

Turning the “fork” option off has no effect.

 

 

Example rule:

package com.siemens.pl.it.rules.test

 

import com.siemens.pl.it.gre.rules.TestObject;

 

 

rule "Is Value 'foo'?"

     

      when

            $testObj : TestObject( value == "foo" )

      then

            $testObj.setResult(true);

           

end

 

 

Interestingly, if I fully-qualify the class in LHS like this: com.siemens.pl.it.rules.test.TestObject( value == "foo" ), the test runs just fine though I would prefer not to have to do this in all my rules if at all possible.

 

Thanks,

-scott