Ant / Eclipse 抱怨 artifact:dependencies

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7335819/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 16:57:55  来源:igfitidea点击:

Ant / Eclipse complains about artifact:dependencies

eclipseantdependencies

提问by Luc

I need to use XML to JSON lib in my war. I followed a tutorialexplaining that dependencies are required in the project.

我需要在我的War中使用 XML 到 JSON 库。我按照教程解释了项目中需要依赖项。

But when I add the following in my ant build.xml(the file used to create the war), Eclipse complains about the artifact:dependencies, seems like it does not like the :.I have the following error message:

但是当我在我的 ant build.xml(用于创建War的文件)中添加以下内容时,Eclipse 会抱怨artifact:dependencies,似乎它不喜欢:。我有以下错误消息:

The prefix artifactfor element artifact:dependenciesis not bound...

artifact元素的前缀artifact:dependencies未绑定...

<artifact:dependencies filesetId="dependency.fileset"
    sourcesFilesetId="sources.dependency.fileset"
    javadocFilesetId="javadoc.dependency.fileset"
    versionsId="dependency.versions">
    <!-- DEPENCIES GO HERE -->
</artifact:dependencies>

Any idea ?

任何的想法 ?

UPDATE

更新

I have the same problem trying to define an in-memory pom with:

我在尝试定义内存中的 pom 时遇到了同样的问题:

<artifact:pom id="mypom" groupId="org.acme" artifactId="project1" version="1.0">
   <dependency groupId="junit" artifactId="junit" version="4.1"/>
   <dependency groupId="org.codehaus.plexus" artifactId="plexus-utils" version="1.5.5"/>
   <license name="apache" url="http://www.apache.org"/>
</artifact:pom>

The prefix artifactfor element artifact:pomis not bound...

artifact元素的前缀artifact:pom未绑定...

UPDATE 2

更新 2

I installed maven-ant jar in ant/lib and change the build.xml so it contains the definition of the artifact stuff but I have an error message while running it.

我在 ant/lib 中安装了 maven-ant jar 并更改了 build.xml,以便它包含工件内容的定义,但在运行它时出现错误消息。

<project name="test" default="install" xmlns:artifact="antlib:org.apache.maven.artifact.ant">

<artifact:dependencies pathId="dependency.classpath">
   <dependency>
        <groupId>net.sf.json-lib</groupId>
        <artifactId>json-lib</artifactId>
        <version>2.3</version>
        <type>jar</type>
        <classifier>jdk15</classifier>
        <scope>compile</scope>
       </dependency>
       ...

The error message Eclipse gave is:

Eclipse 给出的错误消息是:

BUILD FAILED
D:\J2EE\workspace\Test\build.xml:3: Problem: failed to create task or type antlib:org.apache.maven.artifact.ant:dependencies
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:
    -D:\eclipse\plugins\org.apache.ant_1.8.2.v20110505-1300\lib
    -C:\Documents and Settings\luc\.ant\lib
    -a directory added on the command line with the -lib argument

The maven-ant jar does exist in -D:\eclipse\plugins\org.apache.ant_1.8.2.v20110505-1300\lib

maven-ant jar 确实存在于 -D:\eclipse\plugins\org.apache.ant_1.8.2.v20110505-1300\lib

UPDATE 3

更新 3

This is the build.xml file I'm using.

这是我正在使用的 build.xml 文件。

<!--
<project name="Monitoring" default="install" xmlns:artifact="urn:maven-artifact-ant" xmlns:test="urn:test-tasks">
-->
<project name="Monitoring" default="install" xmlns:artifact="antlib:org.apache.maven.artifact.ant">

<!-- project-specific variables -->
<property environment="env" />
<property name="project_home" value="D:\J2EE\workspace\Monitoring"/>
<property name="webapp.dir" value="${project_home}/target" />
<property name="jboss.dir" value="D:\J2EE\jboss\standalone\deployments" />  
<property name="package.name" value="monitoring.war" />
<property name="lib.dir" value="${project_home}/lib" />
<property name="src.dir" value="${project_home}/src" />
<property name="resources.dir" value="${project_home}/resources" />
<property name="dest.dir" value="${project_home}/target" />
<property name="package.file" value="${dest.dir}/${package.name}" />

<!-- put everything in a temp folder with the right structure during the build -->
<property name="temp.dir" value="${project_home}/temp" />
<property name="temp.dir.web-inf" value="${temp.dir}/WEB-INF" />
<property name="temp.dir.lib" value="${temp.dir.web-inf}/lib" />
<property name="temp.dir.classes" value="${temp.dir.web-inf}/classes" />
<property name="temp.dir.meta-inf" value="${temp.dir}/META-INF" />


<path id="build.class.path">
    <fileset dir="${env.JAVA_HOME}/lib">
        <include name="**/*.jar" />
    </fileset>
    <fileset dir="D:\ant\lib">
            <include name="**/*.jar" />
    </fileset>
</path>

<target name="deps">
    <artifact:dependencies pathId="dependency.classpath">
        <dependency>
            <groupId>net.sf.json-lib</groupId>
            <artifactId>json-lib</artifactId>
            <version>2.3</version>
            <type>jar</type>
            <classifier>jdk15</classifier>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-io</artifactId>
            <version>1.3.2</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>xom</groupId>
            <artifactId>xom</artifactId>
            <version>1.1</version>
        </dependency>
    </artifact:dependencies>
</target>

<target name="clean" depends="deps">
    <delete>
        <fileset dir="${dest.dir}" includes="**/*"/>
    </delete>
    <delete dir="${temp.dir}" />
    <delete dir="${temp.dir.classes}" />
    <delete dir="${temp.dir.meta-inf}" />
    <delete dir="${temp.dir.web-inf}" />
</target>

<target name="prepare" depends="clean">
    <mkdir dir="${dest.dir}" />
    <mkdir dir="${temp.dir}" />
    <mkdir dir="${temp.dir.lib}" />
    <mkdir dir="${temp.dir.meta-inf}" />
    <mkdir dir="${temp.dir.web-inf}" />
    <mkdir dir="${temp.dir.classes}" />
</target>

<!-- COMPILE -->
<target name="compile" depends="prepare">
    <echo>=== COMPILE ===</echo>
    <echo>Compiling ${src.dir} files ...</echo>
    <javac debug="on" srcdir="${src.dir}" destdir="${temp.dir.classes}" includes="**/*" includeantruntime="false">
        <classpath refid="build.class.path" />
        <classpath refid="dependency.classpath" />
    </javac>
</target>

<!-- PACKAGE -->
<target name="package" depends="compile">
  <echo>=== PACKAGE ===</echo>

  <!-- copy the config files -->
  <copy file="${resources.dir}/web.xml" tofile="${temp.dir.web-inf}/web.xml" overwrite="true" />
  <copy file="${resources.dir}/manifest.mf" tofile="${temp.dir.meta-inf}/manifest.mf" overwrite="true" />
  <copy todir="${temp.dir.classes}">
    <fileset dir="${src.dir}">
      <include name="**/*.xml"/>
      <include name="**/*.xsl"/>
    </fileset>
  </copy>

  <!-- the ant war task. with all resources in place, create the war file -->
  <war destfile="${package.file}" webxml="${temp.dir.web-inf}/web.xml" basedir="${temp.dir}">
    <lib dir="${lib.dir}" />
    <classes dir="${temp.dir.classes}" />
  </war>
</target>

<!-- INSTALL -->
<target name="install" depends="package">
  <echo>=== INSTALL ===</echo>
  <copy file="${package.file}" tofile="${webapp.dir}/${package.name}" overwrite="true" />
  <copy file="${package.file}" tofile="${jboss.dir}/${package.name}" overwrite="true" />        
</target>

</project>

It was working well before I added all the dependencies stuff... still cannot find out the pb here. Any help would be very welcome.

在我添加所有依赖项之前它运行良好......仍然无法在这里找到 pb。任何帮助将非常受欢迎。

回答by martin clayton

It looks like you're making use of Maven Ant Tasks. To do this you'll need a copy of the jar from the download area here. Once (or if) you've got that, you'll need to modify your buildfile to use it.

看起来您正在使用Maven Ant Tasks。为此,您需要从这里的下载区域获取 jar 的副本。一旦(或如果)你得到了它,你需要修改你的构建文件来使用它。

The main things that are neededare to define the artifactnamespace, and add the typedef for the ant-lib:

需要的主要内容定义artifact命名空间,并为 ant-lib 添加 typedef:

<project name="foo" default="foo" xmlns:artifact="antlib:org.apache.maven.artifact.ant">

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

回答by Emin

I had the same error message but the cause was different.

我有相同的错误消息,但原因不同。

Going to Window -> Preferences -> Ant -> Runtime and setting Ant Home solved my problem.

转到 Window -> Preferences -> Ant -> Runtime 并设置 Ant Home 解决了我的问题。

So for anyone that above solution doesn't work, check if "Ant Home" is pointing to the right direction

因此,对于上述解决方案不起作用的任何人,请检查“Ant Home”是否指向正确的方向