4 useful shell scripts for maven

yeah maven

Maven (2 of course) is the jam when it comes to Java build systems.

Ant is some old timey donkey-mess madness which doesn’t even address the issue of dynamic build dependency resolution.

There are other build systems like: ivy, maven1, and made-up-mess, but the real goodness is the m2 universe.

In addition, to it’s main duties, maven produces a really neat resource in the form of your local repository (mine lives in ${HOME}/.m2/repository).

The dependencies your project pulls in also pull in dependencies and some of them are cool things you didn’t even know you couldn’t live without!

Here are a few scripts I use to leverage a little bit of that powerful force for funtimes!

m2_cp.sh : maven classpath

Maven compiles all your code and runs all your test cases. To do that it has to use an olde timey classpath just like duh, but …. how can you get at it when all you see is your pom.xml?

You can use the olde school trick: mvn -X test -Dmaven.test.skip=true ; and scrap it out of there

Or… you can use my little m2_cp.sh and it will parse it out for you into a file called “m2_cp.txt” that you can use to play more reindeer games.

Like what?

Like packaging up some tarball+script to run your stuff, or some uberJar (though the assembly plugin is a better solution for that), or maybe some…

m2_javap.sh : all your class are… ok…

Almost every Java developer uses an IDE. They pretty much all use eclipse.

I’m in that oddball 0.01% that just uses eclipse as a remote debugger… so… I use a lot of command line tools instead, for example: javap

The javap command will print the method signatures given a list of class names. But… you have to feed it a classpath.

In tricky eclipse, this happens like magic! Neat! But… as a magician, I want to be the magical man… so…

When I’m working on say, a portlet project (from maven-archetype-portlet), and I’m wanting to see some good times, I type: m2_javap.sh javax.portlet.GenericPortlet

Even that too much bother? How ’bout: m2_javap.sh GenericPortlet

m2_latest.sh : to the greatest

Ever use log4j in a project? Ha! Yeah… so now you have a new project and you want to pull it in again… what as the most recent version: m2_latest.sh log4j ; tells you the jar

m2_dep.sh : jar file to dependency

OK, so you need log4j, and the latest is ${HOME}/.m2/repository/log4j/log4j/1.2.14/log4j-1.2.14.jar ; time to start typing that annoying stanza… but wait:

m2_latest.sh log4j | m2_dep.sh

% m2_latest.sh log4j | m2_dep.sh

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>

Script it up

The local repo is really neato! Perfect scripting fodder! Good times…

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: