Maven是杰出的项目管理工具,如今已然代替ANT,成为SCM的老大。但其只是一款项目管理工具,只能通过众多的插件来完成不同的任务,而本身不具有任务执行任务的能力。所以我们在日常开发中,所碰到的一些自定义的需求,不能通过已有插件完成的话,大部分的时候还是需要用ANT来。现在就介绍一下ANT与MAVEN集成的插件。
maven-ant-plugin
一个简单的例子:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.7</version> <executions> <execution> <phase>generate-sources</phase> <configuration> <tasks> <copy todir="${destDir}"> <fileset dir="${sourcedir}"> </fileset> </copy> </tasks> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin>
和普通插件一样,需要goupid, version等。主要的还是在configuration中。
1. 可以直接执行ANT TASK,例如,delete, copy, jar等。具体的ANT task如下 http://ant.apache.org/manual/tasksoverview.html
2. 可以执行ANT 脚本
<configuration> <target> <property name="compile_classpath" refid="maven.compile.classpath"/> <property name="runtime_classpath" refid="maven.runtime.classpath"/> <property name="test_classpath" refid="maven.test.classpath"/> <property name="plugin_classpath" refid="maven.plugin.classpath"/> <ant antfile="${basedir}/build.xml"> <target name="test"/> </ant> </target> </configuration>
3. 部分ANT 命令已经存在于MAVEN中
具体的介绍可见官网 http://maven.apache.org/plugins/maven-antrun-plugin/index.html