Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running ant build gives "package org.junit does not exist"

Tags:

java

junit

ant

When I use a Java IDE to build projects (e.g. NetBeans) that have JUnit tests, they compile fine, but when I try to use ant outside of the IDE to run the build script, I get the error "package org.junit does not exist".

like image 272
Liron Yahdav Avatar asked Nov 24 '09 19:11

Liron Yahdav


3 Answers

You should add your junit.jar into the classpath definition in your ant file.

There are many way to do it, one example is:

<junit printsummary="yes" haltonfailure="yes">
    <classpath>
        <path refid="your.classpath.refid" />
        <fileset dir="${junit.dir}">
            <include name="**/junit.jar" />
        </fileset>
    </classpath>
    ...
</junit>

See Ant Manual for details on setting up your classpath.

like image 162
DJ. Avatar answered Sep 18 '22 13:09

DJ.


The problem was that in the IDE, it set the classpath correctly to include the .jar for JUnit. Running ant outside the IDE, the classpath was different, thus the error. The fix was to put the JUnit .jar in the folder "C:\Program Files\Java\jre6\lib\ext" so it would always be found outside of any IDE.

like image 24
Liron Yahdav Avatar answered Sep 19 '22 13:09

Liron Yahdav


Late answer here.

Copy the junit.jar file to the ${ANT_HOME}/lib folder.

like image 43
NotAgain says Reinstate Monica Avatar answered Sep 16 '22 13:09

NotAgain says Reinstate Monica