使用 Maven ant runner 插件调用 ANT 逻辑,使用 ANT 的subant任务
例子
$ tree
.
|-- pom.xml
`-- src
`-- main
`-- ant
|-- module1
| `-- build.xml
`-- module2
`-- build.xml
5 directories, 3 files
pom.xml
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.myspotontheweb.demo</groupId>
<artifactId>demo</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>compile</phase>
<configuration>
<target>
<property name="src.dir" location="${project.build.directory}/../src"/>
<subant>
<fileset dir="${src.dir}" includes="**/build.xml"/>
</subant>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
ANT 被配置为在 Maven 构建的“编译”阶段运行。ANT 逻辑使用subant任务来运行外部 ANT 逻辑。
运行示例
$ mvn compile
..
..
[INFO] --- maven-antrun-plugin:1.7:run (default) @ demo ---
[INFO] Executing tasks
main:
main:
[echo] module1: hello world
main:
[echo] module2: hello world
[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.394s
[INFO] Finished at: Fri Apr 27 20:25:35 IST 2012
[INFO] Final Memory: 4M/15M
[INFO] ------------------------------------------------------------------------