orgecc


Reducing installed application footprint with compressed executable jars

Posted in java by elifarley on the February 27th, 2007

Though you can significantly reduce the download size of a Java application by applying Pack200 compression to its jars, the installed app size is still the same, since once downloaded, the jars must be expanded.

Wouldn’t it be nice if we could keep all jars tightly compressed even after installing the application ?

It’s already possible to compress applications using UPX - the Ultimate Packer for eXecutables, but it only works for native executable files. What about Java applications ?

Starting from a class created by Ross Judson, I’ve created a small Java tool named XPack, somewhat similar to UPX.

XPack takes a set of jar files, packs them in Pack200 format, and creates one special jar file (*.xpack.jar), which is typically 65% - 76% smaller than the sum of the input jar files, and can be executed as a normal executable jar (the user doesn’t have to unpack it first).

So the difference between an XPack file and a normal Pack200-compressed jar file is that, unlike a Pack200 jar, the user doesn’t have to unpack it before running it.

Ross’ original class has been split in some source files, and now it has these additional features:

  • support for multiple xpack files at runtime. Take this example:
    Suppose you create one xpack file for the main application classes (let’s call it ‘main.xpack.jar’),
    and another xpack file containing all library jars that the application depends on
    (SWT, log4j, etc) named ‘lib.xpack.jar’.
    When you update your application (but not the libraries it depends on),
    you will spare your users from downloading the (possibly bigger) ‘lib.xpack.jar’ file.
    To launch your application, simply double-click the file ‘main.xpack.jar’ or type:
    java -jar main.xpack.jar
    As you see, there’s NO need to specify classpath information like ‘java -cp log4j.jar:swt.jar:blah.jar org.package.MyClass’,
    since all this will be stored in the file ‘main.xpack.jar’.
  • enhanced command-line interface using commons-cli
  • support for custom loaders

To use it, go to the ‘bin’ directory and type ./xpack.sh (or xpack.bat), which will print a brief usage message.
Alternatively, you can call SFXJarPacker.packJar, passing the appropriate parameters.

Please visit the orgecc-xpack project page at http://projects.orgecc.com/orgecc-xpack/ to download it.

The original version of the class ‘PackLoader’ was created by Ross Judson and kindly put in the public domain.
You can find it at compressed-executable-jar

2 Responses to 'Reducing installed application footprint with compressed executable jars'

Subscribe to comments with RSS or TrackBack to 'Reducing installed application footprint with compressed executable jars'.

  1. Sergey said,

    on January 10th, 2009 at 5:31 pm

    Thank you!

  2. Jane Goody said,

    on April 24th, 2009 at 8:07 am

    My friend on Orkut shared this link and I’m not dissapointed that I came to your blog.

Leave a Reply


WP-Highlight