Deliver Your Java Application in One-JAR™!

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


Application frameworks present a challenge to tools like One-JAR because they are written with certain assumed behaviors about classloading which may not always be valid when running under the One-JAR ClassLoader. Because of extensive input from the One-JAR user community, release 0.97 now has extensive (possibly full) support for the following frameworks:
  1. SpringFramework 3.0.2
  2. Google Guice 2.0
Because of the different assumptions about classloading (and in particular, what appears to be a minor omission in the Guice URL resolvers), One-JAR must be configured differently depending on which of the frameworks you wish to use.

The configuration is controlled by a META-INF/MANIFEST.MF setting at the One-JAR top level which names the factory implementation class that implements IURLFactory:

One-Jar-URL-Factory: com.simontuffs.onejar.JarClassLoader$OneJarURLFactory
One-JAR supports custom generation of URL's based on a factory interface in the JarClassLoader:
// Injectable URL factory.
public static interface IURLFactory {
    public URL getURL(String codebase, String resource) throws MalformedURLException;
    public URL getCodeBase(String jar) throws MalformedURLException;
A factory must support getUrl(String codebase, String resource), returning a URL for a resource at a given codebase. It must also support getCodeBase(String jar), returning a URL for a given codebase.

One-JAR comes pre-configured with two factories which return different kinds of URLs:

  • com.simontuffs.onejar.JarClassLoader$OneJarURLFactory -- returns: onejar:/<codebase>/<resource>
  • com.simontuffs.onejar.JarClassLoader$FileURLFactory -- returns: jar:file:<path-to-onejar>!/<codebase>/<resource
The FileURL URL's are injected with a which knows how to tear-apart the "jar:" protocol. FileURL is the best choice for SpringFramework applications, which use "jar:" protocol URL's in their annotation scanners.

The OneJarUrlFactory URL's rely on the global com.simontuffs.onejar.Handler which One-JAR adds to the java.protocol.handler.pkgs system property on startup, so that the URL resolving mechanisms know where to delegate the "onejar:" protocol URL requests.

You can inject your own implementation of IURLFactory into the One-JAR ClassLoader by setting the One-Jar-URL-Factory property to your own implementation of IURLFactory

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