Wednesday, March 13, 2013

Bending Maven to my will

Sometimes you have to let your subconscious chew on something for a month or two before you can digest it. Such is my relationship with Maven.

Last night I dove into Maven: The Complete Reference again with one very specific goal in mind: creating an artifact similar to what Eclipse produces when you export an executable jar with its dependencies in a directory next to it. I came up gasping for air with this solution clenched in my teeth.

The main class is a "Hello, World!" program. It prints its message through slf4j just so I'd have an excuse to bring in some dependencies. Here's the POM:

<project xmlns=""





            <!-- make an executable jar *without* deps -->

            <!-- assemble a zip file with the deps in lib/ -->


And here's the assembly descriptor it references:



This produces a file called It contains a directory called HelloMaven-1.0, which in turn contains the executable HelloMaven.jar and the lib/ directory full of dependencies. The classpath in the manifest of the executable jar correctly references each dependency by its relative path.

I still need to figure out how to attach the zip file to the Maven project (if that's the right term) and automatically deploy it to my repo. But I feel like the tables have turned in my war with Maven. This will make building and deploying Weapon M a breeze, not only for me but for anyone who wants to customize it.

No comments:

Post a Comment