有的時候一個項目用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