The Source for Java Technology Collaboration
User: Password:



Evan Summers

Evan Summers's Blog

Trip and Tick 200: WebStart me up, baby!

Posted by evanx on October 19, 2006 at 03:31 PM | Comments (7)

This article will be updated over time at this permalink.

So today i tried pack200 - and it compresses my jar from 440k to, urm, 110k! OK, so, um, clearly all WebStart jars should be made this way.

Some great resources i found in the process were deployment.dev.java.net which has the important links related to WebStart, and "Deployment Tips and Tricks using WebStart and Java Plugin" (JavaOne2006 PDF slides), which shows you how to lazily load your app via the web, eg. maybe your WebStart app is just a login splash-screen teaser thingymajig that loads your real app in the background, to create the perception of loading a very large app, very quickly. "Mmmm... crumbled-up cookie things."

Previously in "JooJ up your project page with a WebStart demo" we looked at using Netbeans' JNLP tool to create our first JNLP file. This article is the PG13 SNVL version of that, minus the sxx, nudity, and violence - darn it to hell, what a frikkin pity! At least we got the bad language going on, woohoo!

Creating the JNLP

Once we get through the XML with all those angle brackets, we notice that a JNLP file is actually a trivially minimal thing that just specifies our main class, dependent jars, required JRE version, and um, URL thingy.

<jnlp codebase="http://jroller.com/resources/e/evanx/">
  <information>
    <title>QuiteBusy</title>
    <vendor>aptframework.dev.java.net</vendor>
    <icon href="default"/>
    <offline-allowed/>
    <shortcut online="true"/>
  </information>
  <security>
    <all-permissions/>
  </security>
  <resources>
    <j2se version="1.5+"/>
    <jar href="aptfoundation610.jar"/>
    <jar href="cglib.jar"/>
    <extension href="javadb.jnlp"/> 
  </resources>
  <application-desc main-class="quitebusydemo.common.QMessageBusDemo">
       <argument>logger.level=FINEST</argument>
  </application-desc>
</jnlp>

We specify the codebase to be where we upload our jars eg. jroller.com. The all-permissions means we can be naughty, eg. use reflection. Hopefully in future there'll be a some-permissions option.

For testing offline, we would specify the codebase as a local directory where we gonna put we jars.

<jnlp codebase="file:///C:/my/jars">
   ...
</jnlp>

Wrapping Jars signed by others

You can test if a jar is signed as follows, using jarsigner, which is included in the JDK of course (along with keytool, pack200 and javaws).

jarsigner -certs -verbose -verify activation.jar    

If any of your resources are jars signed by others, you gotta wrap those in a JNLP as follows, and put this in the resources section of the JNLP as an extension, as shown above.

<jnlp codebase="http://jroller.com/resources/e/evanx/" href="javadb.jnlp">
  <information>
    <title>JavaDB jar</title>
    <vendor>Signed by Sun Microsystems, Inc</vendor>
    <offline-allowed/>
  </information>  
  <resources>
      <jar href="derby.jar"/>
  </resources>
  <component-desc/>
</jnlp>

Creating a keystore

We create a keystore (file), and a key therein, using keytool (in the JDK).

cd /my/jars
keytool -genkey -keystore myKeystore -alias myself 
keytool -selfcert -alias myself -keystore myKeystore 
keytool -list -keystore myKeystore 
ls myKeystore

Signing the jars

We copy our minty jar and sign it as follows.

cd /my/jars
cp /my/nbprojects/myproject/dist/my.jar .
jarsigner -keystore myKeystore my.jar myself
pack200 my.jar.pack.gz my.jar
javaws my_local.jnlp

pack200 creates my.jar.pack.gz, where we need to have both the original jar, as well as the compressed gz one, in our codebase. The heffalump one is a fallback, eg. for older javaws clients that don't do the pack200 thing.

I keep two JNLP files, one local one (with my local jars directory as the codebase) eg. my_local.jnlp, and then the uploadable one eg. my.jnlp, with the online codebase, eg. on jroller.com. In the above script, i test using the local one, before uploading and testing the online one.

The HTML Link

Now we can insert the JNLP link into our HTML web page as follows.

<a href="http://jroller.com/resources/e/evanx/messagebus610.jnlp">
   <img border="0" src="http://javadesktop.org/javanet_images/webstart.small.gif" alt="Launch"/></a>
<tt>(QuiteBusy, 110k/440k, unsandboxed, Java5)</tt>

Which looks like..

webstart.small.gif (QuiteBusy, 110k/440k, unsandboxed, Java5)

We need to put the alt "Launch" text in the img element, because some people configure their browsers to load images from the "originating" site only, in which case the webstart.small.gif won't show, and they'll see nothing to click on.

You'll want check the server webserver logs (if you can), to make sure it is the pack200'ed my.jar.pack.gz that is getting downloaded :)

Sneak Preview

Here's a sneak preview of some code-matter i wrote today for an article to be published next week or so, or at least a "trailer" for an article - hey, why do they call it a "trailer" when it comes before?! Anyway it's a SwingWorker thingy with a progress dialog built-in, for added convenience.

Launch (ProgressWorkerDemo, 110k/440k, unsandboxed, Java5)


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

  • Pack200 is REALLY useful. We were able to package our app WITH a bundled JVM and still keep the download size very small. In fact, the entire JVM (stripped off using Sun's guidelines AND jars packed with pack200), takes about 7MB of the entire download. That's incredibly small!
    So our entire system, which is quite a big system (server, GUI frontend (webstart), database (hibernate/derby), reporting (BIRT), etc.), has a download size of only 20MB, and does not require any pre-installed JVM.
    Our end-users are incredibly happy: all they need to do is install / upgrade using our installer and they are up and running. We take care of everything...

    Posted by: krakerjaak on October 20, 2006 at 06:21 AM

  • Thanks for bringing up this topic.

    I've been meaning to take another look at Pack200. Last time I never could get it to work properly with my Apache server, I seem to recall some additional step was required and I didn't have enough time to look into it.

    So if you plan on updating this article, please include some details about the server config requirments. Oh, and how to do Pack200 with Ant :)

    Posted by: sialivi on October 20, 2006 at 05:34 PM

  • One thing that bites me consistently with JNLP is that the main class should be in the first jar on the list. I don't know if it's documented somewhere, and it's frankly quite stupid behaviour (you already have all the jars, so why not search them all).

    Posted by: kirillcool on October 20, 2006 at 08:20 PM

  • Very nice article! One addition... the deployment.dev.java.net project also contains the source and jar for the JnlpDownloadServlet and a Pack200 Ant task.

    Posted by: evickroy on October 21, 2006 at 12:08 AM

  • Thanks for the comments, i'll add them into the updated version, which can hopefully serve as an up-to-date resource, for at least myself if no one else :)

    Posted by: evanx on October 21, 2006 at 02:09 AM


  • I've just noticed that jroller.com does not let you upload .gz files, so i've tried again to use java.net CVS as a codebase, and it works. For some reason it didn't when i tried it a few months ago - my firefox would display the JNLP file rather than webstart it.

    Posted by: evanx on October 21, 2006 at 09:20 AM

  • Java.net was unable to handle JNLP files until an upgrade in the server configuration that happened a couple of months ago. So no, it was not just you ;-).

    Posted by: greeneyed on October 21, 2006 at 02:29 PM





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