Brett Porter

Calling Ant Scripts from Maven

Often, people want to get their feet wet with Maven by using it to do the standard things, but to use their existing Ant build that is working fine for complex tasks. This is possible.

To do anything with Maven, you will still need to set up a project.xml file with the information you need to do the Maven tasks you are using.

In the same directory as this project.xml file (and probably in the same place as your ant build) you should create a maven.xml file like so:

You could then run maven do-ant-bit to run the old ant script. Ok, so this isn't that useful yet, but it can be used in conjunction with goal dependencies to start merging an old Ant and new Maven build.

For example, consider you are now building your site with Maven. However you have an old part of your Ant build that generated a few HTML pages that you want copied with the site. Here is a possible solution.

Future steps of integration would be to start importing those small Ant fragments into your maven.xml, or for larger tasks make them reusable and create a Maven plugin that will be available to all your projects.