2015-10-05 31 views
7
錯誤

Ant構建失敗,而在build.xml運行Ant任務運行。我在控制檯得到了以下錯誤:「無法創建任務或鍵入的antlib:org.apache.maven.artifact.ant:MVN」在螞蟻

Buildfile: F:\Eclipse Projects\my_project\build.xml 
    [typedef] Could not load definitions from resource org/apache/maven/artifact/ant/antlib.xml. It could not be found. 

BUILD FAILED 
F:\my_project\build.xml:32: Problem: failed to create task or type antlib:org.apache.maven.artifact.ant:mvn 
Cause: The name is undefined. 
Action: Check the spelling. 
Action: Check that any custom tasks/types have been declared. 
Action: Check that any <presetdef>/<macrodef> declarations have taken place. 
No types or tasks have been defined in this namespace yet 

This appears to be an antlib declaration. 
Action: Check that the implementing library exists in one of: 
     -F:\eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730\lib 
     -C:\Users\Lucky\.ant\lib 
     -a directory added on the command line with the -lib argument 

我放置在Eclipse插件文件夾中的Maven的螞蟻任務的jar文件,並在懷南特ANT_HOME/lib目錄,也包括在classpath中。但它並沒有解決我的問題和this answer也解決不了問題。

回答

15
  1. 在項目中創建的根目錄libmaven-ant-tasks.jar文件放在裏面。
  2. 包括在你build.xml

<path id="maven-ant-tasks.classpath" path="lib/maven-ant-tasks-2.1.3.jar" /> 
<typedef resource="org/apache/maven/artifact/ant/antlib.xml" uri="antlib:org.apache.maven.artifact.ant" classpathref="maven-ant-tasks.classpath" /> 

上述步驟解決了我的問題import語句。希望這對未來的某個人有所幫助。

替代解決方案,

  • 您也可以將maven-ant-tasks.jar文件ANT_HOME/lib文件夾下解決這一問題。
  • 或者你可以有它的Eclipse插件文件夾下。
    例如。 eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730\lib
0

對我來說,我已經有Maven的螞蟻taksk.jar進入目錄'eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730\lib'.

我使用Eclipse,所以我需要的是,去到Ant運行時在菜單窗口>首>螞蟻>運行,選擇"Ant Home Entries",點擊"Ant Home"按鈕E選擇Ant主目錄

'eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730\lib' 

它的工作!