Reputation: 131
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.
Upvotes: 13
Views: 30161
Reputation: 7
Window -> Preferences -> Ant -> Runtime -> Classpath Add junit-xx.jar to the Global Entries as an external jar file.
Upvotes: -1
Reputation: 31
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
Upvotes: 2
Reputation: 6036
I have no clue what it means, but in my case it seems there was a conflict because of Dropbox. Restarting Netbeans resolved the issue. Might have something to do with my using Linux and classmates using Windows, but I'm not sure.
"Just restart Netbeans" might be too simple for a stackoverflow answer, but if someone had posted it, it would have saved me some time...
Upvotes: 0
Reputation: 2730
<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>
Upvotes: 5
Reputation: 7882
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.
Upvotes: 13
Reputation: 38328
I believe that the following is the cause: junit.jar is not in your CLASSPATH environment variable. Either add junit.jar to your CLASSPATH or add it to the classpath that you define in your ant build file.
Here is an introduction to ant.
Upvotes: 0