java - Ant 中的 "Failed to create task or type antlib:org.apache.maven.artifact.ant:mvn"错误

标签 java eclipse maven ant

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

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

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

最佳答案

  1. 在项目的根目录中创建一个lib 目录并将maven-ant-tasks.jar里面的文件。
  2. 在您的 build.xml 中包含 import 语句

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

以上步骤解决了我的问题。希望这对以后的人有帮助。

替代解决方案,

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

关于java - Ant 中的 "Failed to create task or type antlib:org.apache.maven.artifact.ant:mvn"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32950669/

相关文章:

java - 如何让 Eclipse 将文件导出到与源不同的位置?

java - 无法向 openfire 服务器发送消息

java - 以最简单的方式创建和填充数组

java - 为什么我在使用 --option 运行时进行协同设计后无法启动 Java 应用程序

java - 如何在 Spring Boot 中使用 RestTemplate 来保存新对象

eclipse - 如何在 Eclipse 调试器中后退一步?

maven - 依赖项和插件标签中的依赖项有区别吗?

java - 来自 Java 注释处理器的 @SuppressWarnings

java - 为什么会产生 StackOverflowError

android - 无法创建 R.java b/c 项目有错误...由于缺少 R.java 而导致的错误