David Geary's Weblog : WeblogWelcome to David Geary's Blog   

Friday February 03, 2006

Maven Rocks

Since I'm lucky enough to reside in both the Rails and JSF worlds simultaneously, I often get asked what we can do in Java to reap some of the benefits of Rails. I had no idea until recently, but Maven—especially Maven 2—is a heck of a good start.

Maven has been on my list of things to learn for awhile, but it's never made it to the top until I experienced a Maven confluence of sorts, when Shale added Maven support and a client handed me an application built with Maven.

Maven, like Rails, can generate an application for you. Maven 2 has something called archetypes that you can use to generate an application. But the archetype mechanism, much like Rails' code generators, is pluggable. This is really cool; for example, MyFaces has an archetype that will generate a starter MyFaces application. Maven even comes with a plugin that generates IDEA project files. (I'm fresh into IDEA these days)

Now comes the good part. The application that Maven generates for you is setup to work with an impressive array of built-in goals (Maven goals == Ant tasks). So you just do "mvn install", for instance, and watch Maven go through it's paces creating and deploying your newly minted application. You can go pretty far on the built-in goals, but of course, you can also, like, write your own.

One of the barriers to entry for a new technology for me is how easily I can get an app up and running—the so-called 10 minute test. Because Maven can generate a starter application from an archetype created by a third party, I can have a MyFaces application, for example, running in minutes even if I know nothing about MyFaces. Then I can examine the files, learn how it hangs together and extend the app for my own purposes. That saves me an enormous amount of time. (I was hoping Seam would have an archetype, but my searches have failed. Anyone know if there's one available?)

All of this is possible because Maven essentially inverts the structure that Ant users are familiar with. Instead of you implementing build logic with Ant targets, other people implement Maven tasks that you use in your Maven-generated application. That shifts the responsibility of implementing build logic from you to a provider (Maven built-in, MyFaces, whatever) much the same as EJB has forever freed us from the banalities of implementing distributed applications.

One more thing and then I'll send you on your way to someone else's blog. If you're like me, you've got numerous Ant-powered projects and you are committing the cardinal sin of software development: you are repeating yourself. You've got build files all over the place, that essentially do the same thing, but a little differently, for lots of applications and you've got to maintain those build files. You've also got JAR files scattered across your hard disk like goose bumps on the neck of a new Rails convert. Those JAR files have to be maintained too, not to mention the space they eat up.

Instead of bleeding all of this build knowledge all over your drive, Maven encapsulates it in goals that are publicly available and a repository. Like its namesake, Maven accumulates knowledge that you can take advantage of. The Maven repository stores one copy of each of your required JARs at a cool 28 degrees F on your hard drive to ensure maximum freshness. No more JAR files all over the place; Maven gets them from the repository and automatically downloads required dependencies for you. What more could you want?

And I learned not to say much of nothin'
So I figure you already know
But in case you don't, or maybe forgot
I'll lay it out real nice and slow

from Decoration Day by Drive-By Truckers*

* New album due in April, 2006

[Java] ( February 03, 2006 05:35 PM ) Permalink Comments [8]


I totally agree, Maven just makes things easier. It's the closest thing we have in the java space to the rails generation commands and I've found it to be a real time saver. More importantly though it reduces duplication:


Posted by Todd Huss on February 03, 2006 at 06:21 PM MST
Website: http://gabrito.com #

maven makes things easier, when it works. I don't think it is ready for all the use cases you will try throwing at it, even if they are not that complex. I trully hope that in 6 months most of these issues will be gone though.

Posted by Jerome Lacoste on February 04, 2006 at 11:42 AM MST
Website: http://www.coffeebreaks.org/blogs/ #

One of the biggest barriers for me adoption Maven has been the lack of integration into Eclipse. I know it can be done, but only in a kludgy way. Until it's as much of a first-class citizen in Eclipse as Ant is, I think the best I can do is use Ant as a builder that calls Maven tasks for dependency management only.

Unless anyone knows of a high-quality Maven plugin for Eclipse?

Posted by Dan Bradley ( on February 05, 2006 at 10:45 AM MST #

sorry i dislike maven, well, i dislike the dozen's of open source projects that use maven. Invariably mvn doesn't build correctly, or doesn't succeed in 'install'. Perhaps it's just a misunderstanding by those using maven, or perhaps maven is just is a pain in the a** to do right. Ant projects almost always work right. I'll stick with ant.

Posted by Dave Brosius on February 05, 2006 at 10:04 PM MST
Website: http://fb-contrib.sourceforge.net #

Seems really interesting. I haven't given Maven a try yet but I think I just might.

I was wondering though, would there be any chance that a Shale archetype will be available anytime soon? I had a look at Shale after your talk on JavaPolis but I found i quite hard to get going. Maybe an archetype would make things easier.

Posted by Erik Hoogeveen on February 08, 2006 at 01:12 AM MST #

Hi Erik: Yeah, a Maven archetype would be great for Shale. I haven't created an archetype, but I'll look into it. I'd like to have one for Facelets and Seam too.

Posted by David Geary on February 08, 2006 at 10:11 AM MST #

You're in luck. :) We have archetypes for Shale and Struts Action in the Struts svn repository.

We're waiting for the Maven team to release the next version of the archetype plugin, which will allow you to retrieve an archetype from a Maven repo when you type 'mvn archetype:create ...'.

Right now, you have to get the archetype installed into your local Maven repository before it will work.

The README for the Shale archetype, which explains how to check it out and build it, is here: http://svn.apache.org/repos/asf/struts/sandbox/trunk/archetypes/shale-blank/README.txt

A snapshot of the archetype is available here:

You might be able to use 'mvn install:installFile' with the snapshot, but I haven't tried it.

Posted by Wendy Smoak on February 08, 2006 at 10:52 AM MST #

I should've known Wendy had something cooking. Thanks Wendy. btw, the last line of Wendy's email should read:

mvn install:install-file

instead of

mvn install:installFile

Posted by David Geary on February 08, 2006 at 11:57 AM MST #

Comments are closed for this entry.
« Shale Simplifies Remoting | Weblog