首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

Maven3 实施ant任务

2013-01-23 
Maven3 执行ant任务Maven是杰出的项目管理工具,如今已然代替ANT,成为SCM的老大。但其只是一款项目管理工具,

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 ExpressionMaven ExpressionBuilt-in Tasks?Antmaven-antrun-pluginAntCallmaven-antrun-pluginAvailableprofilesBUnzip2maven-assembly-pluginBZip2maven-assembly-pluginChmodmaven-assembly-pluginConditionprofilesCopymaven-resources-pluginDependsetmaven-dependency-pluginEarmaven-ear-pluginFiltermaven-resources-plugin?Note: Filter uses the @...@ token while maven-resources-plugin uses the ?$...?tokenFixCRLFmaven-resources-pluginGenKeymaven-jar-pluginGUnzipmaven-assembly-pluginGZipmaven-assembly-pluginJarmaven-jar-pluginJavacmaven-compiler-pluginJavadoc/Javadoc2maven-javadoc-pluginLoadPropertiesmaven-resources-pluginManifestmaven-jar-pluginPropertymaven-resources-pluginReplacemaven-resources-plugin?Note: Replace can specify its token while maven-resources-plugin uses the ?$...?tokenTarmaven-assembly-pluginUnjarmaven-assembly-pluginUntarmaven-assembly-pluginUnwarmaven-assembly-pluginUnzipmaven-assembly-pluginWarmaven-war-pluginZipmaven-assembly-pluginOptional Tasks?Antlrmaven-antlr-pluginDependmaven-dependency-pluginEJB Tasksmaven-ejb-pluginFTPmaven-deploy-plugin?Note: maven-deploy-plugin can only deploy unto the FTPJavaCCmaven-compiler-pluginJJDocmaven-compiler-pluginJJTreemaven-compiler-pluginJUnitmaven-surefire-pluginJUnitReportmaven-surefire-report-pluginServerDeploymaven-deploy-pluginSetproxymaven-deploy-pluginTranslatemaven-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

热点排行