- maven-antrun-pluginプラグインを使用する
- <ant />タグを使用する
- <ant antfile="Antファイル名" target="実行するtarget名" />
- mavenの実行時クラスパスをantに渡したい場合は<property name="Antに渡すプロパティ名称" refid="maven.runtime.classpath" />でクラスパスを定義する。<ant />タグにinheritRefs="true"を指定する
- targetをmavenの実行引数で変更したい場合は<ant />タグのtarget内を${target}にする。(左記の場合maven引数として-Dtargetを指定する)
下記pom.xmlとbuild.xmlを同ディレクトリに配置して以下のコマンドを実行する。
mvn antrun:run -Dtarget=call
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.7.0</version>
</dependency>
</dependencies>
<configuration>
<tasks>
<property name="classpath" refid="maven.runtime.classpath" />
<ant antfile="build.xml" target="${target}" inheritRefs="true" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</plugin>
</plugins>
</build>
</project>
build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="maven-call-example" default="call" basedir=".">
<target name="call">
<echo message="${classpath}" />
</target>
</project>