"无法在Ant中创建任务或输入antlib:org.apache.maven.artifact.ant:mvn"错误

Luc*_*cky 9 java eclipse ant maven

在运行ant任务时,Ant构建无法运行build.xml.我在控制台中收到以下错误:

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
Run Code Online (Sandbox Code Playgroud)

我将maven-ant-tasks jar文件放在eclipse插件的文件夹和WinAnt ANT_HOME/lib目录中,并且也包含在类路径中.但它没有解决我的问题,这个答案也无法解决问题.

Luc*_*cky 16

  1. lib在项目的根目录中创建一个目录,并将maven-ant-tasks.jar文件放在其中.
  2. 在您的包含中包含import语句 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" />
Run Code Online (Sandbox Code Playgroud)

上述步骤解决了我的问题.希望这对将来有所帮助.

替代解决方案,

  • 您也可以将maven-ant-tasks.jar文件放在该ANT_HOME/lib文件夹下以解决此问题.
  • 或者你可以在eclipse插件文件夹下拥有它.
    例如.eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730\lib


小智 5

就我而言,我已经将 maven-ant-taksk.jar 放入目录中'eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730\lib'.

我正在使用 Eclipse,所以我需要的是,转到菜单 Windows > Preferences > Ant > Runtime 上的 Ant Runtime,选择"Ant Home Entries",单击"Ant Home"按钮 e 选择 Ant 主目录

'eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730\lib'
Run Code Online (Sandbox Code Playgroud)

有效!