Maven-Ant hybrid

Posted on July 20, 2007

Some brief background. Ant is the stock standard Java build system, much as Make is for C/C++. Maven is a newer Java build system which tried to, amongst other things, solver the Jar dependency hell problem, as well as make a standard project directory layout.

From the Maven guide:
src/main/java Application/Library sources
Maven has a central repository for almost all the Jar’s in the world, almost (see here). And within the Maven build file you can specify which jars you would like. For examples, Log4J:
    <dependency>

      <groupId>log4j</groupId>

      <artifactId>log4j</artifactId>

      <version>1.2.9</version>

    </dependency>

Now when you go to compile with maven it goes and gets all the dependencies, puts them in your local repository (~/.m2/repository) and then into your project’s build class path. This is covered in more detail at the Maven website.

What I wanted to achieve was to have both Ant and Maven build systems coexist, so someone without Maven can still use the project as before. And I also wanted to provide the option to use Maven to get the dependencies and put them in the lib directory for Ant to use. Using some pointers I got from here, I produced this ant file, invoked with ant -f ant-deps.xml.This will use your pom.xml to do the dependencies.

The final step is to host your own repository for those 3rd party jars which aren’t hosted elsewhere. Using the doco here I imported all the Jargon jars I had lying around:
mvn install:install-file -Dfile=jargon_v1.4.19.jar -DgroupId=SDSC     -DartifactId=jargon -Dversion=1.4.19 -Dpackaging=jar
SDSC is the group, and probably should have been edu.sdsc or some such thing, but no matter. This command moves the file into your local repository. If you want other to access it, then copy it to a public webserver. In my case I just took the SDSC directory from within my ~/.m2/repositories directory, and hosted it here. Then within the pom.xml file you need to specify this new repository:
  <repositories>

  <repository>

    <id>archer_repo</id>

    <url>http://dev.archer.edu.au/maven</url>

  </repository>

  </repositories>
So what does this give you?
    <li>A good, reliable dependency management system.</li>
    <li>A useful repository system for Jars</li>
    <li>A consistent build layout</li>
    <li>Easier testing (see #1)</li>