---
title: "Maven3 执行ant任务"
author: "lvjun106"
date: "2013-01-14T17:53:27Z"
tags: []
categories: ["企业架构"]
slug: "maven3-ant"
draft: false
lastmod: "2013-01-14T17:53:27Z"
id: 1769613
url: "https://lvjun106.iteye.com/blog/1769613"
---

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`](http://maven.apache.org/plugins/maven-antrun-plugin/) `AntCall` [`maven-antrun-plugin`](http://maven.apache.org/plugins/maven-antrun-plugin/) `Available` [`profiles`](http://maven.apache.org/guides/introduction/introduction-to-profiles.html) `BUnzip2` [`maven-assembly-plugin`](http://maven.apache.org/plugins/maven-assembly-plugin/) `BZip2` [`maven-assembly-plugin`](http://maven.apache.org/plugins/maven-assembly-plugin/) `Chmod` [`maven-assembly-plugin`](http://maven.apache.org/plugins/maven-assembly-plugin/) `Condition` [`profiles`](http://maven.apache.org/guides/introduction/introduction-to-profiles.html) `Copy` [`maven-resources-plugin`](http://maven.apache.org/plugins/maven-resources-plugin/) `Dependset` [`maven-dependency-plugin`](http://maven.apache.org/plugins/maven-dependency-plugin/) `Ear` [`maven-ear-plugin`](http://maven.apache.org/plugins/maven-ear-plugin/) `Filter` [`maven-resources-plugin`](http://maven.apache.org/plugins/maven-resources-plugin/) *Note: Filter uses the @...@ token while maven-resources-plugin uses the  $[]()... token* `FixCRLF` [`maven-resources-plugin`](http://maven.apache.org/plugins/maven-resources-plugin/) `GenKey` [`maven-jar-plugin`](http://maven.apache.org/plugins/maven-jar-plugin/) `GUnzip` [`maven-assembly-plugin`](http://maven.apache.org/plugins/maven-assembly-plugin/) `GZip` [`maven-assembly-plugin`](http://maven.apache.org/plugins/maven-assembly-plugin/) `Jar` [`maven-jar-plugin`](http://maven.apache.org/plugins/maven-jar-plugin/) `Javac` [`maven-compiler-plugin`](http://maven.apache.org/plugins/maven-compiler-plugin/) `Javadoc/Javadoc2` [`maven-javadoc-plugin`](http://maven.apache.org/plugins/maven-javadoc-plugin/) `LoadProperties` [`maven-resources-plugin`](http://maven.apache.org/plugins/maven-resources-plugin/) `Manifest` [`maven-jar-plugin`](http://maven.apache.org/plugins/maven-jar-plugin/) `Property` [`maven-resources-plugin`](http://maven.apache.org/plugins/maven-resources-plugin/) `Replace` [`maven-resources-plugin`](http://maven.apache.org/plugins/maven-resources-plugin/) *Note: Replace can specify its token while maven-resources-plugin uses the  $[]()... token* `Tar` [`maven-assembly-plugin`](http://maven.apache.org/plugins/maven-assembly-plugin/) `Unjar` [`maven-assembly-plugin`](http://maven.apache.org/plugins/maven-assembly-plugin/) `Untar` [`maven-assembly-plugin`](http://maven.apache.org/plugins/maven-assembly-plugin/) `Unwar` [`maven-assembly-plugin`](http://maven.apache.org/plugins/maven-assembly-plugin/) `Unzip` [`maven-assembly-plugin`](http://maven.apache.org/plugins/maven-assembly-plugin/) `War` [`maven-war-plugin`](http://maven.apache.org/plugins/maven-war-plugin/) `Zip` [`maven-assembly-plugin`](http://maven.apache.org/plugins/maven-assembly-plugin/) Optional Tasks   `Antlr` [`maven-antlr-plugin`](http://maven.apache.org/plugins/maven-antlr-plugin/) `Depend` [`maven-dependency-plugin`](http://maven.apache.org/plugins/maven-dependency-plugin/) `EJB Tasks` [`maven-ejb-plugin`](http://maven.apache.org/plugins/maven-ejb-plugin/) `FTP` [`maven-deploy-plugin`](http://maven.apache.org/plugins/maven-deploy-plugin/) *Note: maven-deploy-plugin can only deploy unto the FTP* `JavaCC` [`maven-compiler-plugin`](http://maven.apache.org/plugins/maven-compiler-plugin/) `JJDoc` [`maven-compiler-plugin`](http://maven.apache.org/plugins/maven-compiler-plugin/) `JJTree` [`maven-compiler-plugin`](http://maven.apache.org/plugins/maven-compiler-plugin/) `JUnit` [`maven-surefire-plugin`](http://maven.apache.org/plugins/maven-surefire-plugin/) `JUnitReport` [`maven-surefire-report-plugin`](http://maven.apache.org/plugins/maven-surefire-report-plugin/) `ServerDeploy` [`maven-deploy-plugin`](http://maven.apache.org/plugins/maven-deploy-plugin/) `Setproxy` [`maven-deploy-plugin`](http://maven.apache.org/plugins/maven-deploy-plugin/) `Translate` [`maven-resources-plugin`](http://maven.apache.org/plugins/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