3

I literally wasted 2 hours trying to get ant junit task working. First, I had trouble finding ant-junit.jar file but I managed to find it in a maven page. After that I put it several places(~/.ant/lib, /usr/share/ant/lib) but no luck.. I'm still getting this error:

Cause: the class org.apache.tools.ant.taskdefs.optional.junit.JUnitTask was not found.
        This looks like one of Ant's optional components.

So I'm looking for:

  1. Official web page to download ant junit task files
  2. Correct place to put that file.
Dave Newton
  • 158,873
  • 26
  • 254
  • 302
sinan
  • 6,809
  • 6
  • 38
  • 67

2 Answers2

2

1. The Ant download distribution

Expurgated tree:

➜  apache-ant-1.9.4  tree lib
lib
├── ant-junit.jar
├── ant-junit4.jar

2. Your test classpath

Just like any other test dependency.


Tangential: The distro (or a Maven repo/search) is generally the first place to look. It’s a few minutes to download, decompress, look for the JUnit-related files, and do a tar xvf to sanity-check the missing class ref.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
1

You can download dependencies from Maven Central from an ANT task as follows:

<available classname="org.junit.runner.Runner" property="junit.installed"/>

<target name="install-junit" description="Install junit" unless="junit.installed">
    <mkdir dir="${user.home}/.ant/lib"/>

    <get dest="${user.home}/.ant/lib/ant-junit.jar" src="http://search.maven.org/remotecontent?filepath=org/apache/ant/ant-junit/1.9.4/ant-junit-1.9.4.jar"/>
    <get dest="${user.home}/.ant/lib/junit.jar" src="http://search.maven.org/remotecontent?filepath=junit/junit/4.11/junit-4.11.jar"/>

    <fail message="Ivy has been installed. Run the build again"/>
</target>

An even better alternative is to use Apache ivy to manage dependencies. An example build file is here:

Community
  • 1
  • 1
Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185