Adam Bien's Weblog

How to reduce the Jar-File size with Java5 and 6

Java SE 5 and 6 comes already with a packing tool called "pack200". This tool is able to compress already existing jar files which can be then used for network distribution. I compressed the rt.jar with the following command:

C:\Programme\Java\jdk1.6.0\jre\lib>pack200 -J-Xmx256m rt.jar.gz rt.jar

The flag -J-X.. is needed, because otherwise OutOfMemory exception can occur (pack200 is written in Java...)
The results are amazing:

Origin size: 43.8 MB
Compressed size: 5.81 MB

For unpacking the tool "unpack200" can be used.

The tool pack200 is especially interesting for the distribution of WebStart applications to achieve faster download times. There is already one another well known sample - glassfish. In the second installation stage, glassfish unpacks internal libraries using the unpack200 tool...


NEW workshop: Microservices with Java EE 7 and Java 8, January 26th, 2015, Airport Munich

A book about rethinking Java EE Patterns

Comments:

Actually, the JRE unpacks rt.jar form pack200 at install time. Also note that WebStart applications compressed with pack200 should (Sun says must) be deployed with a specific servlet to deliver the packed (or not) JAR files.

Posted by Romain Guy on December 29, 2006 at 04:59 AM CET #

Though the actual average compression rate would be at about 50%. I don't know how you managed to get from 41 MB to 5 MB.

Posted by CeciNEstPasUnProgrammeur on May 20, 2010 at 03:38 PM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed
realworldpatterns.com
...the last 150 posts
...the last 10 comments
License