Thursday, August 31, 2006

Add jars to manifest file using Maven2

It's not easy to find how we can customize maven plugins.
There's poor documentation for plugins on maven site.
You should spend much time in maillist or looking plugin source codes to understand how you can customize plugin behavior.

Some time ago i wanted to make running my JARs more easy. I wanted to put all depending jars to manifest file. So i put in pom.xml such customization:




<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>fully.qualified.MainClass</mainClass>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>



Now when maven packages my project it creates in manifest file classpath references:

Class-Path: antlr-2.7.6.jar commons-logging-1.0.4.jar ....

And I can easy start my jar without long classpath string just type: java -jar myproject.jar

No comments: