Maven
Wow. I have to admit to being a little late to the party on this one. Several years ago, my days as a full-time Java developer where filled with ant (if you were lucky) and make (if you weren’t).
Before I continue, this evenings late night festivities are brought to you by this (ultimate) form of nourishment:
And this fantastic album:
Anyhoo, this evening, I planned on spending a couple hours playing with hibernate (I wanted to check out its ORM capabilities, especially compared to Rails ActiveModel (which I love)). 5 minutes into the tutorial and I was in jar-hell and for the millionth time starting thinking “where do I download that that mysql-connector-java” (its here for those of you that care) as I started to think about hooking hibernate up-to mysql.
But not this time. Introducing maven. The best description of that I can think of is ant coupled with something like yum or apt-get or macports or whatever. Its kind of like a RubyGems for jar files.
Here’s a sample POM file, from the hibernate tutorial:
<modelVersion>4.0.0</modelVersion> <groupId>org.hibernate.tutorials</groupId> <artifactId>hibernate-tutorial</artifactId> <version>1.0.0-SNAPSHOT</version> <name>First Hibernate Tutorial</name> <build> <finalName>${artifactId}</finalName> </build> <dependencies> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>3.3.2.GA</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.9</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId> <version>1.5.11</version> </dependency> <dependency> <groupId>javassist</groupId> <artifactId>javassist</artifactId> <version>3.8.0.GA</version> </dependency> </dependencies> </project>
The bit we care about are the dependencies. Lets kick off a build:
~/java/tutorial $ mvn compile [INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [INFO] Building First Hibernate Tutorial [INFO] task-segment: [compile] [INFO] ------------------------------------------------------------------------ Downloading: .../maven-plugins-12.pom Downloading: .../maven-parent-9.pom Downloading: .../apache-4.pom Downloading: .../maven-plugins-8.pom Downloading: .../maven-parent-5.pom ...
And look at that bad boy go! Good lord, it actually fetched 40 jars, stored them locally in my repository, and used them in the build. Dependencies and everything. Glorious. I have to admit to being more impressed this evening with maven than hibernate (which is actually fine, I’m just a little spoilt with ActiveModel).
The source for the hibernate tutorial is here for safekeeping.
Tomorrow I need to burn 44 gigs of VMWare instances onto DVDs and post them to a data-center in Florida. Wonder how long it will take. I figure its easier than trying to FTP them.