Run Ant from Maven

You may have one of these needs:

  • You or your team have to use Ant but you are have Maven and do not want everyone to config Ant on their local computer.
  • You want to just ‘mvn install’ and let Maven does Ant tasks.

Then this page is for you.

Full Code:

2_maven_with_ant.zip

What you need to run this:

  • Maven 3

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:

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

What does these codes do?

These lines,

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:

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.

After this, you can just try to run this command in your console:

Then you will see this:

See the line number 4 there.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">