*
The moose likes Ant, Maven and Other Build Tools and the fly likes JUnit not found... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "JUnit not found..." Watch "JUnit not found..." New topic
Author

JUnit not found...

Rami Sawas
Ranch Hand

Joined: Jan 25, 2004
Posts: 41
I typed 'ant' and I get this error:
JUnit not found in Ant's CLASSPATH!
How do I set the CLASSPATH? I prefer using DOS in these issues.
Thank you.
Billybob Marshall
Ranch Hand

Joined: Jan 27, 2004
Posts: 202
Put junit.jar in your %ANT_HOME%/lib directory
Rami Sawas
Ranch Hand

Joined: Jan 25, 2004
Posts: 41
It's already there...
To make sure, how would I set the CLASSPATH in DOS command.
Thanks again.
Billybob Marshall
Ranch Hand

Joined: Jan 27, 2004
Posts: 202
Originally posted by Rami Sawas:
It's already there...
To make sure, how would I set the CLASSPATH in DOS command.
Thanks again.

You don't set the CLASSPATH. When you run 'ant' (which is a bat file), it sets and uses its own classpath, built from the jars it finds in the lib directory. So my guess is you are running some other 'ant' script, not the one that comes with ant.
Rami Sawas
Ranch Hand

Joined: Jan 25, 2004
Posts: 41
Well basically, I downloaded a shopping cart from the Internet and trying to make it work after downloading the necessary software.
The build.xml in the Framework\Lab directory (shoppinf cart)uses an external entity to basically import buildCommon.xml that is in the top directory. That file defines where many libraries like Xerces and Xalan should be found. I unzipped Xerces and Xalan to different directories then I either have to move them or modify buildCommon.xml to point to them.
I modified alot of buildCommom.xml to match my files. But there are few sections which I left them as they are maybe you could help me out.
The code below is quiet big. I couldn't reduce it less than that because I thought I would give you a clear picture of what buildCommon.xml includes. I've removed bits which I think are not related to Ant-Junit.
There are bits which are bold either need to be changed but don't know how or don't what they represent(in other words are they important to be there).
Thank you.

<property name="junitRoot" value="C:"/>
<property name="antDir" value="${antRoot}/apache-ant-1.6.0"/>
<property name="junitDir" value="${junitRoot}/apache-ant-1.6.0"/>
<property name="ant" value="${antDir}/lib/ant.jar"/>
<property name="buildDir" value="classes"/>
<property name="docDir" value="doc"/>
<property name="docRoot" value="docroot"/>
<property name="javadocDir" value="${docDir}/api"/>
<property name="junit" value="${junitDir}/lib/ant-junit.jar"/>
<property name="libDir" value="lib"/>[/B]
<property name="srcDir" value="src"/>[/B]
<property name="util" value="Util/classes"/>

<target name="cleanTestLogs" description="deletes generated JUnit log files">
<delete>
<fileset dir=".">
<include name="TEST-*.txt"/> <!-- generated by the test target -->
</fileset>
</delete>
</target>

<target name="compile" depends="prepare" description="compiles source files">
<javac srcdir="${srcDir}" destdir="${buildDir}"
classpathref="classpath" deprecation="on"/>
</target>

<target name="compileUtil" unless="utilCompiled"
description="compiles Util source files">
<ant dir="../../Util" target="compile"/>
</target>

<target name="init" description="performs initialization steps">
<parallel>
<available property="haveJUnit"
classpath="${junit}" classname="junit.framework.TestCase"/>
</parallel>
</target>
<target name="javadoc" depends="compile"
description="generates javadoc from all .java files">
<delete dir="${javadocDir}"/>
<mkdir dir="${javadocDir}"/>
<javadoc sourcepath="${srcDir}" destdir="${javadocDir}"
packagenames="com.*" classpathref="classpath"/>
</target>

<target name="prepare"
depends="init,verifyant-junit,verifyMySQL,verifyTomcat,verifyXalan,verifyXerces"
description="create output directories">
<parallel>
<mkdir dir="${buildDir}"/>
<mkdir dir="${docDir}"/>
<mkdir dir="${libDir}"/>
<available property="utilCompiled" file="Util/classes"/>
</parallel>
</target>

<target name="run" depends="compile" description="runs main class">
<java classname="${mainClass}" classpathref="classpath" fork="yes"/>
</target>

<target name="test" depends="compile,cleanTestLogs"
description="runs all ant-junit tests">
<ant-junit fork="yes" printsummary="yes">
<classpath refid="classpath"/>
<batchtest>
<fileset dir="${srcDir}">
<include name="**/*Test.java"/>
</fileset>
<formatter type="plain"/>
</batchtest>
</ant-junit>
</target>
<target name="verifyant-junit" unless="haveant-junit">
<fail message="ANT-JUnit not found in Ant's CLASSPATH!"/>
</target>

<target name="zip" description="zips files in this directory">
<zip zipfile="${zipFile}" basedir="."
excludes="${zipFile},${buildDir}/**,${javadocDir}/**"/>
</target>
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
<target name="verifyant-junit" unless="haveant-junit">

Where do you set your haveant-junit property?
[ February 07, 2004: Message edited by: Marilyn de Queiroz ]

JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Rami Sawas
Ranch Hand

Joined: Jan 25, 2004
Posts: 41
Whenever you see ant-junit, it's the same as junit. The reason for having 2 names is that I changed the name 'junit' to 'ant-junit' to match the name of the file in my ANT directory.
Is it a problem if I change the name of the file to match the code?
Anyway, I'm keeping it as 'jnuit'.
<target name="init" description="performs initialization steps">
<parallel>
<available property="haveJUnit"
classpath="${junit}" classname="junit.framework.TestCase"/>

<available property="haveMySQL" file="${mysqlDir}" type="dir"/>
<available property="haveTomcat" file="${tomcatDir}" type="dir"/>
<available property="haveXalan" file="${xalan}" type="file"/>
<available property="haveXerces" file="${xercesImpl}" type="file"/>
</parallel>
</target>

By the way, when I type in 'ant -v', it gave me this...
'Unable to load class junit.framework.TestCase'
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
It seems to me that if you set a property named haveJUnit that you would need to test for a property named haveJUnit and not for a property named haveant-junit.

I would suggest that you try changing one of them so they are identical, whichever one you prefer -- haveant-junit or haveJUnit.
Rami Sawas
Ranch Hand

Joined: Jan 25, 2004
Posts: 41
I've changed everything to 'junit' but still face the same problem. "Junit" was already in the ANT folder under the name "Ant-Junit" so I just changed it to "Junit" ..hope it doesn't cause much of a problem.
I'm actually worried about these 3 pieces of code. I copy/paste exactly from builCommon.xml
<target name="compile" depends="prepare" description="compiles source files">
<javac srcdir="${srcDir}" destdir="${buildDir}"
classpathref="classpath" deprecation="on"/>
</target>
<target name="compileUtil" unless="utilCompiled"
description="compiles Util source files">
<ant dir="../../Util" target="compile"/>
</target>
<target name="init" description="performs initialization steps">
<parallel>
<available property="haveJUnit"
classpath="${junit}" classname="junit.framework.TestCase"/>
</parallel>
</target>
Don't I have to put some kind of an actually value or directory instead of "classpath"?
Don't I have to put some real directory instead of ".../../Util"
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JUnit not found...
 
Similar Threads
Assertion
NullPointer running junit on DOMElementWriter.encode
Integrating JUnit with Ant
AssumptionViolatedException with JUnit but Why and how to Solve?
How can I solve this error?