2015-10-05 29 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' 

它的工作!