Full Code:

What you need to run this:

Explain:

Our goal is that we want to run ‘mvn install’ and Maven will run a target in an Ant build file (build.xml)

Assume that you have the Ant build file, build.xml, look like this:

XHTML

1

2

3

4

5

<project name="mavn_with_ant_example"basedir=".">

<target name="install">

<echo message="Hello from ANT" />

</target>

</project>

It will just print “Hello from ANT” to console.

To hook our Ant build with ‘mvn install’, you need to add Ant plugin in pom.xml

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

<build>

<plugins>

<plugin>

<artifactId>maven-antrun-plugin</artifactId>

<version>1.8</version>

<executions>

<execution>

<id>install_all</id>

<phase>install</phase>

<goals>

<goal>run</goal>

</goals>

<configuration>

<tasks>

<ant antfile="build.xml"

target="install"/>

</tasks>

</configuration>

</execution>

</executions>

</plugin>

</plugins>

</build>

What does these codes do?

These lines,

1

2

3

4

<phase>install</phase>

<goals>

<goal>run</goal>

</goals>

Basically, it just hooks ant to maven goal. It means that “when the run goal of the install phase is running, run my antrun plugin” In the other words, when you run ‘mvn install’ it will run this antrun plugin.

Then this line:

XHTML

1

2

3

4

5

<configuration>

<tasks>

<ant antfile="build.xml"target="install"/>

</tasks>

</configuration>

It means that the antrun plugin will run the install target in build.xml . Do not be confused the install target with ‘mvn install’ , they are not related.