Note that there are some explanatory texts on larger screens.

plurals
  1. POAnt JUnit task NoClassDefFoundError when run in existing JVM
    primarykey
    data
    text
    <p>I went for the <strong>JUnit Ant task</strong> solution where I provide the <strong>JUnit library</strong> through the task's element:</p> <pre><code>&lt;target name="test" depends="compile-tests" description="Run unit tests"&gt; &lt;junit printsummary="true" haltonfailure="true"&gt; &lt;classpath refid="test.classpath" /&gt; &lt;test name="com.package.TestClass" /&gt; &lt;/junit&gt; &lt;/target&gt; </code></pre> <p>The important classpaths used are:</p> <pre><code>&lt;path id="test.compile.classpath"&gt; &lt;path refid="compile.classpath" /&gt; &lt;path refid="test.lib.classpath" /&gt; &lt;pathelement location="${build.classes.dir}" /&gt; &lt;/path&gt; &lt;path id="test.classpath"&gt; &lt;path refid="test.compile.classpath" /&gt; &lt;pathelement path="${test.classes.dir}" /&gt; &lt;/path&gt; </code></pre> <p>And the referenced one with the junit.jar is an <strong>Ant Maven task</strong>:</p> <pre><code>&lt;artifact:dependencies pathId="test.lib.classpath"&gt; &lt;dependency groupId="junit" artifactId="junit" version="4.11" /&gt; &lt;/artifact:dependencies&gt; </code></pre> <p>Now, the problem is that I get an exception when running this task:</p> <pre><code>java.lang.NoClassDefFoundError: junit/framework/TestListener </code></pre> <p>The solution is adding the <strong>fork="true"</strong> attribute to the task:</p> <pre><code>&lt;junit printsummary="true" haltonfailure="true" fork="true"&gt; </code></pre> <p>My questions are:</p> <ul> <li>Why without running a new JVM instance does the JUnit Ant task fail to include the junit.jar in the runtime?</li> <li>And what is this runtime actually? Is it the one executing the Ant script? Is attaching a jar to the runtime impossible? I thought it would be standard class loading.</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload