Core Java Books

Thursday, 3 March 2011

Using Google Code to Host WebStart Applications

As you can see from my previous posts I like to provide examples applications and not just some code. Initially I wasn't sure how I could provide WebStart applications via my blog. After some investigation it turned out to be fairly easy, here are some notes about how to go about it.

To start with I obviously needed to create applications that can be delivered as WebStart applications. Personally I use Netbeans for all my development and this make it very easy. You simply select in your projects preferences that it will be packaged as a WebStart application and provide some basic information. When you build a WebStart application a JNLP file will be created and also on e or more Jar files.

Secondly I needed somewhere to host my files. I decided to use project hosting, which is provided by Google Code. You create a project and select the source revision method you wish to use. I picked SVN as its something I know well and is supported by default by Netbeans. Basically this allows you to store you project on the Google Code servers and update them whenever you want.

So now we have a JNLP file, a Jar or Jars and a way of storing these remotely on the Google Code servers.

Now in a JNLP file some of the fields need to specify the location of the JNLP and also the Jars to be used. You need to make sure these are set correctly. In the example below I have highlighted what I needed to change.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jnlp codebase="" href="youjnlpfilename.jnlp" spec="1.0+">
        <homepage href=""/>
        <description kind="short">Something useful</description>
<update check="always"/>
<j2se version="1.5+"/>
<jar href="YourJar.jar" main="true"/>
    <application-desc main-class="">

You should change these fields as appropriate for where your application is hosted, the name of the application and the jars and main class to be used.

One other thing you need to make sure the mime type is set correctly for the JNLP file, otherwise any request to obtain it will just be passed a text file, we want it to kick off the Java VM and start running the application. Netbeans allows you to easily add mime types for files by adding it as a SVN property. This needs to be set so the Google Hosting Server know how to deliver the JNLP file back to any requester. The mime type should be set as:

Property name: svn:mime-type 
Property value: application/x-java-jnlp-file

If you don't use Netbeans then you can set the mime type using SVN:

$ svn propset svn:mime-type application/x-java-jnlp-file my.jnlp

Now we have the files hosted, the mime type is set we now need to add the link into our blog/webpage. Oracle/Sun provide a handy standard bit of script for this :) Just add the following into you page:

<script src="">

And in theory that is it :)


Please +1 this post or pass it on if you think it is useful.

No comments:

Post a Comment