Skip to main content

Maven for Ant Users

My coworker asked me to describe how Maven compares and differs to Ant. I realized how hard it was for me to describe what a developer gets for moving their build process from Ant scripts to Maven. I can't make the argument that you can do X with Maven but not with Ant because I don't really have a valid example. However, I am inclined to make the argument that you can do X with both but with Maven it's easier.

With Maven, you collect metadata about your project instead of writing scripts defining the steps your build will take. For example, if you look at an Ant script you'll immediately see that it is organized as targets which many developers use to define and group the steps of their build process. In a Maven POM file, you won't see similar build steps defined. This can be confusing for a new Maven user coming from the world of Ant. I know it was for me. Instead, you'll see lots of metadata about the project such as dependencies, Maven plugins to use, locations for the source control repository and project website, the working directory structure, contributors and more, but nothing that defines what should happen when you want to build the project's jar, or generate a documentation site for the project. These steps are defined by various Maven plugins.

Maven plugins are the most tangible thing you get from using Maven over Ant. What the plugins provide are nothing you can't do with Ant, but they encompass many of the tasks Ant users have written and rewritten time and time again. Goals like compiling your classes, running your unit tests, jaring your classes, generating javadoc, building a JAR of your source files, and on and on. So if you want to build your project with Generics support, you'll define in your Maven POM file that the compiler plugin should target JDK 5.0, but you won't have to define what Maven needs to do to complete the goal.

So when it comes time to build your project, you haven't spent anytime rewriting goals, instead you've only spent time describing how your project differs from other projects. So when you call "mvn jar:jar" instead of "ant jar", you won't have written any of the boilerplate script to tell Ant how to build a jar and which steps it depends on (compile, test), you'll just have reused the jar goal that a Maven developer wrote.

With Maven you get to focus on the high-level task of defining your project instead of the low-level task of defining your build.

Comments

sheldon said…
This comment has been removed by a blog administrator.
jaXzin said…
This comment has been removed by the author.
sheldon said…
This comment has been removed by a blog administrator.
jaXzin said…
This comment has been removed by the author.

Popular posts from this blog

TeamCity build triggering by GitHub

So I started using GitHub for a side project and discovered their very cool feature of service hooks. A service hook allows a repository administrator to setup a callback to another service when a commit is made to the repository. For example it can send an email, or chat a message via Jabber.

Now continuous integration servers, like TeamCity, can poll source control systems every few minutes to see if any changes have been committed. But wouldn't it be more efficient to use a service hook to trigger a build?
Looking at GitHub's service hooks, there wasn't one already available to callback a TeamCity server, but right on that same page was a link to the open source repository for GitHub Service Hooks. They "eat their own dogfood" so to speak and make it very easy to contribute new service hooks back to them. So I took an evening, did my first Ruby coding in a while which included more time getting Ruby setup and working on my Macbook than actually coding. In a …

Paperless

I've been slowly going paperless over the past decade. The first step on my journey started in 2000 when I signed up to use a payment service, PayTrust, to receive my incoming bills, scan them, and put them online for me to pay. The next major step was probably when I got a digital camera to replace my traditional film cameras. It might not be considered a "paperless" use case, but it has lead to very little hardcopies over the years as monitors and HDTV with screensavers and AppleTVs have become so beautiful.  Back to the paperless office, my next big step was eFileing my taxes but that didn't come until about 5 years later. Then suddenly about two years ago, I hit a real shift in my desire to go completely paperless when I got my iPad and installed Evernote.

digital notes...
If you aren't familiar with Evernote its an excellent app, available on all the major desktop and mobile OSes, that makes note-taking and organizing really simple. The killer feature is …

My Journey to Fitness, a 5K, and my first Triathlon

My name is Brian and Sunday I became a triathlete. My journey started ten months ago when I decided to get back into shape after 15 years of being obese and out-of-shape with some yo-yo dieting in the middle. What changed? I'll get to that.
This weekend I competed in the first ever Rocketman Florida Triathlon which took place on the grounds of Kennedy Space Center at Cape Canaveral. In preparation I lost 50 lbs and 12 inches from my waist. But I'm getting ahead of myself.
I'm a huge space buff. As a kid I wanted to become an astronaut. I went to Space Camp in Titusville when I was 10. Before that, I saw my first shuttle launch at 7 while on vacation. It was the final launch of the Challenger. I've written about that experience. I've seen three other launches since then including John Glenn's famous return to space as well as the final launch that ended the U.S. Shuttle Program.
The idea of biking on the restricted grounds and getting closer than any civilian h…