2014-09-02 83 views
2

我從字面上浪費了2個小時試圖讓ant junit任務工作。首先,我無法找到ant-junit.jar文件,但我設法在maven頁面中找到它。從那以後,我把它放在幾個地方(~/.ant/lib/usr/share/ant/lib),但沒有運氣..我仍然收到此錯誤:ant junit任務 - 在哪裏下載ant-junit.jar以及在哪裏放置它?

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

所以我在尋找:

  1. 官方網頁下載ant junit任務文件
  2. 放置該文件的正確位置。

回答

1

螞蟻下載分發

刪減樹:

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

2.您的測試類路徑

就像任何其他的測試依賴。

(無關,但不會發行版是絕對第一地方,你想看看嗎?這「字面意思是」花了5分鐘下載,解壓縮,尋找JUnit的相關文件,並做了tar xvf理智檢查缺少類REF)

1

您可以從Maven Central從一個Ant任務下載的依賴關係如下:

<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> 

一個更好的替代方法是使用Apache常春藤管理的依賴關係。一個例子構建文件是在這裏: