1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
<?xml version="1.0"?>
<document>
<properties>
<author email="bob@eng.werken.com">bob mcwhirter</author>
<title>Uberjar</title>
</properties>
<body>
<section name="Maven Uberjarring">
<p>
Pete Kazmier has written the
<a href="http://jakarta.apache.org/turbine/maven/reference/plugins/uberjar/">uberjar plugin for maven</a>.
</p>
<p>
Simply set (in your project.properties) the <code>maven.uberjar.main</code> property to
the name of your "main" class, and type:
</p>
<source>
maven uberjar
</source>
<p>
An uberjar containing your project's jar and all dependencies will be created for you.
</p>
</section>
<section name="Manual Uberjarring">
<p>
<code>classworlds</code> 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
<code>java -jar myapp.jar</code> type of execution.
</p>
<p>
To create a standalone jar (aka, an uberjar), simply build your application's
jar as normal. Gather up all dependent jars and create a <code>classworlds.conf</code>
for your application. Similar to other jar formats, a meta-directory is
created within the uberjar, named <code>WORLDS-INF/</code>. It contains
two directories:
<ul>
<li><code>WORLDS-INF/lib/</code>
<p>to contain all jars required by your application.</p></li>
<li><code>WORLDS-INF/conf/</code>
<p>to hold your <code>classworld.conf</code> file.</p></li>
</ul>
</p>
<p>
The <code>classworlds.conf</code> should be created as normal, with the special
exception that the property <code>${classworlds.lib}</code> points to the internal
library directory <code>WORLDS-INF/lib/</code> so that jars can be loaded from
within the uberjar:
</p>
<source>
[app]
${classworlds.lib}/myApp.jar
${classworlds.lib}/someDependency.jar
</source>
<p>
The core <code>classworlds</code> jar needs to be placed at the root of the
<code>WORLDS-INF</code> directory, named <b>exactly</b> <code>classworlds.jar</code>
</p>
<p>
Create the required directory structure, and populate it with the appropriate
files. For example:
</p>
<source>
./assembly-dir/
WORLDS-INF/
classworlds.jar
lib/
myApp.jar
someDependency.jar
anotherDependency.jar
conf/
classworlds.conf
</source>
<p>
All that remains is unjaring the classes from <code>classworlds-boot.jar</code> into
your assembly directory and creating your final jar. The final layout should appear like:
</p>
<source>
./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
</source>
<p>
Now, simply create and distribute your standalone uberjar:
</p>
<source>
cd assembly-dir/
jar cvf myapp-standalone.jar .
java -jar myapp-standalone.jar
</source>
</section>
</body>
</document>
|