Tuesday, November 23, 2010

Ant vs Maven

Ant is "Another Neat Tool" that lets you do builds by writing instructions in XML. Need to compile using javac? use <javac>. Need to make make a jar? Use the <jar> task. You define "targets" to run and dependencies... It is neat if you don't mind crafting XML. Ant scripts are usually quite followable. Go head, spend a few minutes with ANT for fun. EVERY java programmer should know a thing or two about ANT.

Waita minute... just why am I wrapping commands with tags? Ok, here is why. ANT is cross platform and batch file stinks.. it is hard to make targets and stuff in a batch file.

Maven is the newer XML based tool that lets you do builds and much more. It is a new approach... you don't follow Maven scripts like an ANT script. Go ahead, spend 5 minutes with Maven.
Every java programmer should also know a thing or two about Maven also.

The following is instant-turn-off, you want me to type WHAT?

mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app
-DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false


Ooh, it generates a pom.xml for me and even some tests. Test Driven aficionados would instantly fall in love with it.

The big feature of Maven is dependencies handling. Most programs nowadays are not all made by your home grown parts... You may have the Log4J component, you may have Struts, Spring, Hibernate. Normally you would need to download all that stuff and jam your classpath with all those dozens of jars to build. With Maven, it will download those jars for you in the repository.
Your pom.xml does not contain the nuts and bolts of the command to compile your stuff and make the jar... they are behind the scene.

1 comment:

Alex Mak said...

Java EE apps are complex horrible monsters. Just the nested directories along will drive any programmer insane. Therefore the world need generators like maven. The world also need frameworks; each framework is outrageously difficult, yes, Rails is difficult too.

Maven have emerged to be the leader and have since displaced Ant (good, I hate Ant) and automake, which displace good old Makefile. (I LOVE the simple elegance of Makefile).

So for programmers there is no choice but to embrace Maven. The 5 minute tutorial is pretty good.