Deliver Your Java Application in One-JAR™!

Copyright 2004-2010 by P. Simon Tuffs, All Rights Reserved.

Building Using Ant

Creating a One-JAR file requires no special tools: the Java jar command is all that is necessary. However, the hierarchical nature of One-JAR files can prove complex to construct, even when automated within an Ant script.

There is a simple way: an Ant task called <one-jar> has been created. This task extends the Ant <jar> task, so it should be immediately familiar and usable to those experienced with Ant. To construct a One-JAR file using this task, simply include the XML fragment that defines the taskdef, and invoke the target.

An outline of the <one-jar> task is shown below:

    <one-jar destfile=... manifest=...>
            Attributes for the manifest of the One-JAR.  Use this instead of
            specifying a "manifest" attribute above
            <attribute name="attr" value="value">
            ... etc.
    	<main [jar="main.jar"]>
    		<filesets> which comprise the class-files of the main application.  
    		Do not put JAR files in here; rather use the "jar" attribute if you already have a 
    		pre-canned main program.
    		<filesets> containing Jar-files which support the main application.
    		<filesets> containing native libraries.  Native libraries are expanded into a 
    		temporary directory at runtime: these files are deleted on exit.
    		<filesets> containing class-loader wrappers.  These check classloaders 
    		that are loaded from the supporting Jar files to make sure they are compatible 
    		with the One-JAR classloader. This is a complex subject, contact one-jar-support for
    		more information and consulting services if you need to wrap a classloader.
    		You will know you need this if your application does not load classes when
    		you expect it should, from JAR files inside the <lib> directory.
    		Any other stuff you want in the top-level One-JAR file.  Remember though, any
    		.class files you put in here will not be able to "see into" JAR files loaded
    		from /main and /lib because their classloader will be the top-level Java 
    		Application Loader, which does not understand One-JAR files (this is how One-JAR 
    		came about in the first place). Contact one-jar support if you find 
    		yourself having problems with this kind of issue.

If you like One-JAR then you might want to check out some of the other Open-Source projects developed by
Get One-JAR(TM) at Fast, secure and Free Open Source software downloads soap-stone at Eclipse JAR Plugin Yet Another Compiler Compiler Language