|
|
||||||||||||||||||||||||||||||||||||||||||||||||
I've been working on an application which can be deployed via Java Web Start. One nice think about Web Start is that it will use content negotiation with the server to download highly compressed jar files when they are available.
The documentation includes sample Servlet code to handle the negotiation, which is nice, but I didn't want to run a Servlet container just for this. Thankfully I ran across Keith Lea's blog entry Guide: How to use Pack200 for your Java Web Start applications on Apache Web Server which shows how to use Apache's own content negotiation modules and eliminates the need for any Servlets. However, it seemed like it could still be made a little simpler. In particular, I didn't like having to create a "type map" for each compressed jar. What follows is what I think is the simplest possible configuration for getting this to work on Apache 2.
Add the following to your global httpd.conf file:
AddType application/x-java-jnlp-file .jnlp AddType application/x-java-archive .jar <Files *.jar.gz> AddEncoding x-gzip .jar ForceType application/x-java-archive </Files> <Files *.jar.pack.gz> AddEncoding pack200-gzip .jar ForceType application/x-java-archive </Files>
In each folder where you will serve jar files from, add
an .htaccess file with these lines:
Options +MultiViews MultiviewsMatch Any
That's it for configuration! Now you just have to drop the right jars
into the folder with the .htaccess file. If your original
jar is named foo.jar, you should put the following into the
folder:
foo.jar.unpackedfoo.jar.gzfoo.jar.pack.gzFor my application these three jars were 823, 698, and 234 kilobytes, respectively. Because Web Start auto-updates those bytes can really add up in saved bandwidth costs over time.
Here is a simple shell script which will take a single unpacked jar file and create the three necessary files:
#!/bin/sh gzip -c $1 > $1.gz pack200 $1.pack.gz $1 mv $1 $1.unpacked
Note that renaming foo.jar
to foo.jar.unpacked is a critical step. The Apache
MultiViews feature will disregard the compressed jars and always
serve foo.jar if it actually exists. You don't have to use
the .unpacked suffix, just make sure to tack on
something.