Pete Kazmier has written the uberjar plugin for maven.
Simply set (in your project.properties) the maven.uberjar.main
property to
the name of your "main" class, and type:
maven uberjar
An uberjar containing your project's jar and all dependencies will be created for you.
classworlds
allows the creation of a single standalone
jar for your project which may internally include any other additional
jars that are required for your application. This allows for easy
java -jar myapp.jar
type of execution.
To create a standalone jar (aka, an uberjar), simply build your application's
jar as normal. Gather up all dependent jars and create a classworlds.conf
for your application. Similar to other jar formats, a meta-directory is
created within the uberjar, named WORLDS-INF/
. It contains
two directories:
WORLDS-INF/lib/
to contain all jars required by your application.
WORLDS-INF/conf/
to hold your classworld.conf
file.
The classworlds.conf
should be created as normal, with the special
exception that the property ${classworlds.lib}
points to the internal
library directory WORLDS-INF/lib/
so that jars can be loaded from
within the uberjar:
[app] ${classworlds.lib}/myApp.jar ${classworlds.lib}/someDependency.jar
The core classworlds
jar needs to be placed at the root of the
WORLDS-INF
directory, named exactly classworlds.jar
Create the required directory structure, and populate it with the appropriate files. For example:
./assembly-dir/ WORLDS-INF/ classworlds.jar lib/ myApp.jar someDependency.jar anotherDependency.jar conf/ classworlds.conf
All that remains is unjaring the classes from classworlds-boot.jar
into
your assembly directory and creating your final jar. The final layout should appear like:
./assembly-dir/ WORLDS-INF/ classworlds.jar lib/ myApp.jar someDependency.jar anotherDependency.jar conf/ classworlds.conf com/ werken/ classworlds/ boot/ Bootstrapper.class InitialClassLoader.class protocol/ jar/ Handler.class JarUrlConnection.class
Now, simply create and distribute your standalone uberjar:
cd assembly-dir/ jar cvf myapp-standalone.jar . java -jar myapp-standalone.jar