I am a bit new to JUnit and Ant. I want to know what this error means:
The <classpath> for <junit> must include junit.jar if not in Ant's own classpath
I am compiling a Java project, and I cannot get beyond this point.
The documentation of the Junit ant task gives a list of options for how to get junit.jar onto the classpath:
http://ant.apache.org/manual/Tasks/junit.html
To save you the lookup, the options are reproduced below. My preference is option 1.
<property name="lib.dir" value="webcontent\WEB-INF\lib" />
<path id="classPath">
<pathelement location="${lib.dir}/junit-4.11.jar" />
</path>
<target name="test" depends="build">
<junit haltonerror="false" haltonfailure="false" fork="yes">
<classpath path="${lib.dir}">
<path refid="classPath" />
</classpath>
</junit>
</target>
I spent a couple hours with this problem today. I had the .jar files all specified in Eclipse via Project|Properties|Java Build Path, but was still getting the
<classpath> for <junit> must include junit.jar if not in Ant's own classpath
error when running Ant from Eclipse.
Running Ant from the command line would work fine (I had everything in the classpath environment variable).
But in Eclipse the only thing that worked was to explicitly state the classpath inside the elements, e.g.:
<path id="JUnit 4.libraryclasspath">
<pathelement location="...\plugins\org.junit_4.11.0.v201303080030\junit.jar"/>
<pathelement location="...\plugins\org.hamcrest.core_1.3.0.v201303031735.jar"/>
<pathelement location="...\lib\ant-junit4.jar"/>
</path>
<path id="Ant1.classpath">
<pathelement location="bin"/>
<pathelement location="."/>
<path refid="JUnit 4.libraryclasspath"/>
</path>
... stuff...
<target name="test1" depends="compile">
<junit>
<classpath refid="Ant1.classpath"/>
</junit>
</target>
Without explicitly specifying the classpath within the junit element, it would break in eclipse every time, even just a bare
<junit/>
reference
I'm no expert, just reporting what worked today.
-ctb
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With