Maven3 执行ant任务

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中

Ant Expression Maven Expression
Built-in Tasks  
Ant maven-antrun-plugin
AntCall maven-antrun-plugin
Available profiles
BUnzip2 maven-assembly-plugin
BZip2 maven-assembly-plugin
Chmod maven-assembly-plugin
Condition profiles
Copy maven-resources-plugin
Dependset maven-dependency-plugin
Ear maven-ear-plugin
Filter maven-resources-plugin Note: Filter uses the @...@ token while maven-resources-plugin uses the  $... token
FixCRLF maven-resources-plugin
GenKey maven-jar-plugin
GUnzip maven-assembly-plugin
GZip maven-assembly-plugin
Jar maven-jar-plugin
Javac maven-compiler-plugin
Javadoc/Javadoc2 maven-javadoc-plugin
LoadProperties maven-resources-plugin
Manifest maven-jar-plugin
Property maven-resources-plugin
Replace maven-resources-plugin Note: Replace can specify its token while maven-resources-plugin uses the  $... token
Tar maven-assembly-plugin
Unjar maven-assembly-plugin
Untar maven-assembly-plugin
Unwar maven-assembly-plugin
Unzip maven-assembly-plugin
War maven-war-plugin
Zip maven-assembly-plugin
Optional Tasks  
Antlr maven-antlr-plugin
Depend maven-dependency-plugin
EJB Tasks maven-ejb-plugin
FTP maven-deploy-plugin Note: maven-deploy-plugin can only deploy unto the FTP
JavaCC maven-compiler-plugin
JJDoc maven-compiler-plugin
JJTree maven-compiler-plugin
JUnit maven-surefire-plugin
JUnitReport maven-surefire-report-plugin
ServerDeploy maven-deploy-plugin
Setproxy maven-deploy-plugin
Translate maven-resources-plugin Note: Translate can specify its own tokens and can have a different encoding scheme for reading and writing files. maven-resources-plugin however uses the  $... annotation only and has only one encoding scheme for reading and writing

具体的介绍可见官网 http://maven.apache.org/plugins/maven-antrun-plugin/index.html

猜你喜欢

转载自lvjun106.iteye.com/blog/1769613