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

Introduction

Hi everybody,
I'm starting this blog to share my experience in Java and relative technologies.
I'm java server side developer and I'll write in my blog about things I'm interested in :
  • ORM (Hibernate, TopLink)
  • Web frameworks (Tapestry, RIFE, JSF, Struts)
  • IoC (Spring, HiveMind)
  • AJAX (GWT, Yahoo, JSON RPC)
  • AOP
  • Building tools (Maven2, Ant)
  • IDE (IDEA, Eclipse)
  • and whatever i use and want to use
But if i find interesting thing in "desktop" word, i'll post such things too.

There're many tools, frameworks in java ocean and it's hard to choose right one. I think here we can find the right tool for every situation.