ant junit task — where to download ant-junit.jar and where to put it?

旧时模样 提交于 2020-01-02 07:30:13

问题


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


来源:https://stackoverflow.com/questions/25628253/ant-junit-task-where-to-download-ant-junit-jar-and-where-to-put-it

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!