首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ant中“无法创建任务或类型antlib:org.apache.maven.artifact.ant:mvn”错误

Ant中“无法创建任务或类型antlib:org.apache.maven.artifact.ant:mvn”错误
EN

Stack Overflow用户
提问于 2015-10-05 22:09:25
回答 2查看 18K关注 0票数 9

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

代码语言:javascript
复制
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也不能解决这个问题。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-10-05 22:09:25

  1. 在项目的根目录中创建一个lib目录,并将maven-ant-tasks.jar文件放入其中。
  2. 在您的build.xml

中包含import语句

代码语言:javascript
复制
<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 plugins文件夹下。

例如:eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730\lib

票数 18
EN

Stack Overflow用户

发布于 2018-02-05 21:27:14

在我的例子中,我已经将maven-ant- the sk.jar放到了'eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730\lib'.目录中

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

代码语言:javascript
复制
'eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730\lib'

啊,真灵!

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32950669

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档