There are various approaches to getting started with One-JAR. Ant users will find the "Application Generator Approach" most useful,
Maven users the "Maven Approach", command-line tool users may prefer the "Command Line Approach".
Application Generator Approach
This approach provides you with a complete Eclipse/Ant application directory, which you can
use as a starting point for your own One-JAR application. The application generator
is driven by a template built into the one-jar-appgen.jar file (see
Add source code to the
- Download one-jar-appgen-0.97.jar
- Generate application, build, and run it.
$ 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
$ cd build
$ java -jar test-one-jar.jar
test_one_jar main entry point, args=
test_one_jar main is running
src directory, library jars to the
The use of Ant is not required: a One-JAR archive is simple to build using just the
jar tool using the following steps.
You should end up with a One-JAR archive which mirrors the "root" tree:
- Create a working directory to act as the "root" of the one-jar with
- Copy your main application jar file into
root/main and library dependencies into
- Unjar the
one-jar-boot-0.97.jar file into the root directory, and delete the "src" tree
- Edit the boot-manifest.mf file and add a new line:
Note: make sure that your final one-jar contains a manifest that looks like this:
- cd root; jar -cvfm ../one-jar.jar boot-manifest.mf .
| Boot.class, ...etc.
| 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.
There is a Maven2 plugin for One-JAR. It is easy to use for Maven projects. Please
consult the documentation here: http://code.google.com/p/onejar-maven-plugin/
Ant Taskdef Approach
Detailed use of the One-JAR Ant Taskdef is discussed
here. Note that the
uses the Ant taskdef.
Use of the (deprecated) SDK is discussed