| <<Background | Home Print Layout | Ant Taskdef>> |
$ java -jar one-jar-appgen-0.97.jar
Enter project path (project name is last segment): c:/tmp/test-one-jar Enter java package name: com.example.onejar
$ cd c:/tmp/test-one-jar
$ ant
$ cd build
$ java -jar test-one-jar.jar
test_one_jar main entry point, args=[] test_one_jar main is running test_one_jar OK.
src directory, library jars to the lib directory,
and rebuild.
jar tool using the following steps.
main, lib sub-directories.root/main and library dependencies into root/libone-jar-boot-0.97.jar file into the root directory, and delete the "src" treeOne-Jar-Main-Class: your-main-class
Note: make sure that your final one-jar contains a manifest that looks like this:
Manifest-Version: 1.0 Main-Class: com.simontuffs.onejar.Boot One-Jar-Main-Class: YOUR.MAIN.CLASS.NAME.HERE
one-jar.jar | META-INF/MANIFEST.MF | .version | com/simontuffs/onejar | Boot.class, ...etc. | doc/one-jar-license.txt | main/main.jar | lib/a.jar ...etc.Thats it: no code to write, just a directory tree, some copy operations, and a file edit. The One-JAR classloader discovers the libraries and main code based on their position in the archive, and ignores any other Jar files should you need to embed archives which should not be on the classpath. Embedding the
one-jar-license.txt ensures compliance
with the BSD-style license.
one-jar-appgen approach
uses the Ant taskdef.