antlib and classpathref

2019-05-26 11:01发布

I have the following build.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<project name="Minimal" default="default" basedir="." xmlns:artifact="antlib:org.apache.maven.artifact.ant">
    <path id= "libs.folder" >
         <fileset dir= "lib" >
             <include name= "*.jar" /> 
         </fileset>
    </path>

    <typedef resource="org/tigris/subversion/svnant/svnantlib.xml" classpathref="libs.folder" /> 
    <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="libs.folder"/>
    <artifact:pom id="pom.file" file="pom.xml" />
    <property name="pom.version" value="${pom.file.version}"/>

   <groovy src="test.groovy">
    <arg line="3"/>
   </groovy>
...

which is located in the following structure:

my-project
  -> lib
     -> maven-ant-tasks.jar
     -> svnant.jar
     -> groovy-all.jar
     -> svnClientAdapter.jar
  -> build.xml
  -> pom.xml
  -> test.groovy

when I run the build file I get:

BUILD FAILED
....\build.xml:18: Problem: failed to create task or type antlib:org.apache.maven.artifact.ant:pom
Cause: The name is undefined.
Action: Check the spelling.

If I run with:

ant -lib lib

it works but it could be nice to keep everything inside the build.xml file - like with the groovy and svnant libs.

is this possible with the maven-ant-tasks.jar somehow?

标签: ant classpath
2条回答
2楼-- · 2019-05-26 11:25

Copy both maven-ant-tasks-2.x.x.jar and maven-ant-tasks-2.x.x.pom to /lib.

http://search.maven.org/#search|ga|1|a%3A%22maven-ant-tasks%22

Note: Read more at http://maven.apache.org/ant-tasks/

查看更多
Luminary・发光体
3楼-- · 2019-05-26 11:40

When you use:

xmlns:artifact="antlib:org.apache.maven.artifact.ant"

without a typedef, the libs for that have to be in ANTS CLasspath. That is ANT_HOME/lib or ${user.home}/.ant/lib or any folder specified with -lib. Thats why ant -lib lib works.

If you change it to a typedef like the other antlibs, it will work.

<typedef resource="org/apache/maven/artifact/ant/antlib.xml"
           uri="antlib:org.apache.maven.artifact.ant"
           classpathref="libs.folder" />
查看更多
登录 后发表回答