The Source for Java Technology Collaboration
User: Password:



Francois Orsini

Francois Orsini's Blog

Compressing Apache Derby w/ Pack200

Posted by forsini on April 29, 2006 at 11:26 PM | Comments (3)

PACK200 (JSR-200) is a very interesting feature that is available as part of Java 5.

In order to increase network server, availability and bandwidth , two new compression formats have been made available to Java deployment of applications and applets: gzip and Pack200.

HTTP compression is implemented in Java Web Start and Java Plug-in in compliance with HTTP 1.1 RFC 2616. If a client does not support this type of compression then a web server will send a non-compressed JAR or a format that the client can process.

More information about Pack200 at:
http://java.sun.com/j2se/1.5.0/docs/guide/deployment/deployment-guide/pack200.html

I have compressed the Apache Derby engine JAR file (derby.jar) using pack200 and the resulting JAR went from 2,131,777 to 630,520 bytes (~2MB down to 600K for the database core engine!). Uncompression happens on the client side automatically once the pack200 compressed JAR has been fetched.

To compress/pack the JAR archive:
$ pack200 derby.jar.pack.gz derby.jar

It then can be stored on a HTTP 1.1 compliant web server and if a web client support pack200-gzip encoding (specified as part of the HTTP request), then the server will send that compressed JAR down - otherwise the server will stream/send a format that the client can process (compressed {gzip} or not {.jar}).

To unpack (manually):
$ unpack200 derby.jar.pack.gz derby.jar (the unpack operation is actually pretty fast)

This is quite good when one needs to deploy Apache Derby over a network (i.e. Applet using Derby with the Java plug-in, etc) or as part of some installer who would want to pack JARs even more efficiently and then unpack them during install (unpack200{.exe} is a standalone executable that can be included as part of an installer)

pack200 and unpack200 are pure executable(s) that do not require a JVM to be present or run at the time an archive is compressed or uncompressed (i.e. during installation)

unpack200 (Unix) or unpack200.exe(Windows) included as part of the JRE as well (under bin)

Pack200 also has a Java API (java.util.jar.Pack200):
http://java.sun.com/j2se/1.5.0/docs/api/java/util/jar/Pack200.html
The packer engine is used by application developers to deploy or host JAR files on a website. The unpacker engine is used by deployment applications to transform the byte-stream back to JAR format.

This does not reduce the runtime footprint of Apache Derby - it basically provides means to reduce the network footprint of JARs during download. Pack200 also supports the packing of *signed* JARs.


Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment

  • Hello

    We have pack200 compliant files on the webserver. However, some JVM, like 1.5.07, working with IE6 SP1 do not ask for pack200 format. Instead they "only" ask for gzip or deflate. It looks as wether only 2/3 of all pack200 compliant JVMs get the new format.

    Any ideas?

    Posted by: vonbarru on June 30, 2006 at 04:52 AM

  • If you're using the (Sun) Java Plug-in with IE, then handling decompression of PACK200 files returned by a web server should work - which (vendor) JVM are you using?

    Posted by: forsini on July 07, 2006 at 08:02 PM

  • As you've mentioned, using Pack200 alone doesn't reduce the runtime footprint of a Java application. To accomplish that, you may want to take a look at this post:

    Reducing installed application footprint with compressed executable jars

    Posted by: elifarley on February 27, 2007 at 12:14 PM



Only logged in users may post comments. Login Here.


Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds