Maven OR Ant? Maven AND Ant?

There is too much controversy of moving from Ant to Maven, but maybe people don’t know that ant build scripts can be used with maven.

These are the step by step instructions:

  1. Create a minimal project.xml, that we’ll call POM (Project Object Model) or project descriptor. The most tedious task will be adding the dependencies needed to compile your classes, but you can use this search tool to get groupId and artifactId for them. If any of that dependencies are not at ibiblio repository copy the url of the repo, you’ll need it later. Change sourceDirectory to suit your needs.
  2. Create a file maven.xml. This is the place to write ant scripts. You just have to rename targets to goals. You can get the current dir using ${basedir}.
    <?xml version="1.0" encoding="ISO-8859-1"?>
      <goal name="doSomething">
        <!-- do some stuff using ant scripts -->
        <delete dir="${basedir}/adir"/>
        <mkdir dir="${basedir}/adir" />
        <copy todir="${basedir}/adir">
          <fileset dir="${basedir}/anotherdir"/>
  3. If you use some dependency not at ibiblio create a file with a line maven.repo.remote=, where is the url you copied early. You can add as much urls as you want, separated by commas.
  4. Now you can run maven doSomething to execute the ant goal, and you can also call maven java:compile to compile the classes, maven site to generate a good looking website,…
  5. A common complain of Ant users is speed. You can call maven doSomething java:compile to run both goals or use maven console, where ypu can type any goal without the startup penalty time.
  6. Now you should be ready to check maven reference docs to explore the lots of features that maven can offer.

To sum up you can do with Maven everything you can do with Ant and many more things, so why don’t give it a try?

8 thoughts on “Maven OR Ant? Maven AND Ant?

  1. I could not agree more. Why the controversy?

    Maven does everything ant can do. In fact it uses the Ant tasks, plus it does much much more.

    Maven can really mitigate Jarmaggedon!

    To me using Maven is a no brainer.

  2. Re: the_mindstorm
    It doesn’t try to download the same everytime, just when needed and the same jars are not redownloaded. And it does it for you, if you wan to do the same things you do with Maven you’d have to download by hand.

  3. wow, I beg to differ. I just looked at Magic and I was *really* impressed by it. It seems like everything maven should have been. Let me add that I think Maven/Jelly is great and was ahead of its time, but its kitchen-sink philosophy makes it not very practical for a lot of projects.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s