Posted by evanx
on October 31, 2006 at 5:08 PM PST
Roll your own multi-stage jar loader, using pack200, jars within jars, and webservers within, um, Swing apps!
align=left vspace=4 hspace=8 />
So I've been playing with URLClassLoader, URLConnection, jars within jars, and webservers within, um, Swing apps. All quite Escher'esque.
The article about the demo, is served by the webserver within the demo :)
Actually there is a copy of the "article" here ,
and the project page is
So we embed a jar within a jar so that we can wrap a
pack200 jar in a real jar. But then the wrapper gets to be like a "splash jar" ie. a splash screen written in java, so we got carte blanche, sweeet!
In this demo, the splash jar uses URLClassLoader to load the "real" jars. We have one embedded jar (containing demo's as in the menu below), and we also preload an external jar eg. the last item in the menu below. It's disabled until that jar is loaded (off jroller.com). Then that menu item becomes enabled, and you can launch it.
In order to use URLClassLoader for this twisted purpose, we embed a webserver, which is what makes
this exercise real fun :)
The code is in webservlet/src .
You can of course run it by checking out the webservlet.dev.java.net project and running the main class cookiejar.CookieJarLoader.
Here is the "raw" CookieJar, ie. a jar file that your browser might be willing to download and run for you with one click?
(webservlet, 150k, executable java5 jar)
The CookieJar pops up the above JFrame as soon as your browser finishes downloading it, and decides to run it using java, woohoo!
If your browser doesn't run jars, then here is the JNLP of the above jar.
(CookieJar, 150k, all-permissions, Java5)
No security... Goddamn, i wish i knew how to sandbox stuff properly?!
Um, er... so what is this 150k jar? Well... it contains a few things. (1) an article, (2) another jar with my old boring dinky demos in it, and (3) a webserver, to serve up (1) and (2).
I must confess, i had a huge amount of fun putting this
twisted demo together! :)