ant引用maven的依赖

有的时候一个项目用Maven做了依赖,可是又脱离不开ant打包, 这个时候maven的依赖jar包就成了在ant打包过程中必不可少的资源.通过maven-ant-task可以解决这部分问题.

1.下载maven-ant-tasks.2.1.3.jar


2.有两种方式可以引用此功能:

(1)拷贝maven-ant-tasks.2.1.3.jar到%ant_home%/lib下.

在build.xml中的<project>标签中加入内容:xmlns:artifact="antlib:org.apache.maven.artifact.ant"

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


(2)拷贝maven-ant-tasks.2.1.3.jar到项目目录任意位置,比如放在项目的根目录,也就是${basedir}下.

在build.xml中的<project>标签加入同(1)相同的内容,同时加入以下两行:

<path id="maven-ant-tasks.classpath" path="${basedir}/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" />

官方版本的下载地址为:

http://apache.opencas.org/maven/ant-tasks/

内容参见官方的Installation:
http://maven.apache.org/ant-tasks/installation.html

3.在build中使用artifact:dependencies.如果没有前边的安装过程,会报artifact前缀找不到的错误.

<artifact:dependencies filesetId="mavenlib" pathId="mavenclasspath" useScope="runtime">    
    <pom file="pom.xml" />
</artifact:dependencies> 

<copy todir="${lib.dir}">    
    <fileset refid="mavenlib" />    
    <mapper type="flatten" />
</copy> 

<javac destdir="${target.class.dir}" deprecation="on" encoding="UTF-8" 
includeantruntime="false">    
    <src path="${src.dir}"/>    
    <classpath refid="mavenclasspath" />
</javac>

其中filesetId供拷贝jar包时引用, pathId供编译时引用

其它使用方法参见:

http://maven.apache.org/ant-tasks/examples/dependencies.html





你可能感兴趣的:(maven,ant,maven-ant-tasks)