有的时候一个项目用Maven作了依赖,但是又脱离不开ant打包, 这个时候maven的依赖jar包就成了在ant打包过程当中必不可少的资源.经过maven-ant-task能够解决这部分问题.html
1.下载maven-ant-tasks.2.1.3.jarjava
2.有两种方式能够引用此功能:web
(1)拷贝maven-ant-tasks.2.1.3.jar到%ant_home%/lib下.apache
在build.xml中的<project>标签中加入内容:xmlns:artifact="antlib:org.apache.maven.artifact.ant"app
<project ... xmlns:artifact="antlib:org.apache.maven.artifact.ant">...<project>
(2)拷贝maven-ant-tasks.2.1.3.jar到项目目录任意位置,好比放在项目的根目录,也就是${basedir}下.maven
在build.xml中的<project>标签加入同(1)相同的内容,同时加入如下两行:ui
<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" />
官方版本的下载地址为:spa
http://apache.opencas.org/maven/ant-tasks/code
内容参见官方的Installation:
http://maven.apache.org/ant-tasks/installation.html
orm
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