ant junit task — where to download ant-junit.jar a

2019-05-14 07:11发布

问题:

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.

回答1:

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.

(Unrelated, but wouldn't the distro be the absolute first place you'd look? It "literally" took me five minutes to download, uncompress, look for the JUnit-related files, and do a tar xvf to sanity-check the missing class ref.)



回答2:

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:

  • sample example which explain how to use filesystem resolver


标签: java ant junit