Executable jar with onejar-maven-plugin

Onejar-maven-plugin collects your application including dependencies, into one executable jar. It's both easy and works well!

Problem

If you have ever tried doing this before with Maven, you have probably used maven-assembly-plugin, which would leave the door open for classpath problems!

It would extract all your dependency jars in one directory together with all your class files and all other classpath resources. The problem is that everything ended up in a big mix, with classpath resources possibly overwriting each other. For example, if two dependencies each had a log4j.properties file in their jar, one log4j.properties would overwrite the other.

No more of that mess!

Solution

Enter maven-onejar-plugin. It lets all your dependency jars stay jars, and your code is in its own jar. All of those jars are put in a bigger jar, which is made executable.

Configuration

It may sound weird, but it's quite elegant! Just put this in your pom.xml's tag to make it work:

   org.dstovall   onejar-maven-plugin   1.3.0                        your.package.YourMainClass                       one-jar                

You also need to add this to the pom:

        onejar-maven-plugin.googlecode.com     http://onejar-maven-plugin.googlecode.com/svn/mavenrepo    

Reference:

http://code.google.com/p/onejar-maven-plugin/

http://onejar-maven-plugin.googlecode.com/svn/mavensite/usage.html

http://blog.jayway.com/2009/03/22/executable-jar-with-onejar-maven-plugin/


留言

這個網誌中的熱門文章

Disable ionic's sidemenu content drag to toggle menu

Multiple writable mappings exist for the field. Only one may be defined as writable, all others must be specified read-only.

java.lang.NoClassDefFoundError: org/apache/xerces/jaxp/datatype/XMLGregorianCalendarImpl$Parser