Hash Verifier 0.3.0.1 (Java Web Start)

Java Web Start is a technology that allows easy deployment of Java based software through a web browser. The advantages of this framework are numerous but one nice thing is that it allows you far more freedom then the completely sandboxed Java applet. In this post I will detail how I converted my Hash Verifier application to run right from the browser.

Java Network Launching Protocol (JNLP)

The javax.jnlp libraries provide the functionality needed to launch the application from within a web browser. This is done through the use of a specially crafted XML file called a jnlp file. This file specifies the application information including the location of the executable jar and any class libraries associated with it. The nice thing about this is that it allows you to specify different class files spending on the platform it is being run on. This is exactly what I needed in order to get the correct SWT libraries loaded on the target platform.

As an example of what a jnlp file looks like here is the file I created for my Hash Verifier application:

<?xml version=”1.0″ encoding=”utf-8″?>
<jnlp spec=”1.0+” codebase=”http://www.tylerburton.ca/webstart” href=”hv.jnlp”>
<information>
<title>Hash Verifier</title>
<vendor>tylerburton.ca</vendor>
<homepage href=”http://tylerburton.ca” />
<description>A graphical file digest generator</description>
<description>Hash Verifier</description>
</information>

<security>
<all-permissions />
</security>

<resources>
<j2se version=”1.5+” />
<jar href=”HashVerifier.jar” />
</resources>

<resources os=”Windows” arch=”x86″>
<jar href=”http://www.tylerburton.ca/swt/3.6.1/swt-win32-windows-x86.jar” />
</resources>

<resources os=”Windows” arch=”x86_64″>
<jar href=”http://www.tylerburton.ca/swt/3.6.1/swt-win32-windows-x86_64.jar” />
</resources>

<resources os=”Windows” arch=”amd64″>
<jar href=”http://www.tylerburton.ca/swt/3.6.1/swt-win32-windows-x86_64.jar” />
</resources>

<resources os=”Linux” arch=”ppc”>
<jar href=”http://www.tylerburton.ca/swt/3.6.1/swt-gtk-linux-ppc.jar” />
</resources>

<resources os=”Linux” arch=”ppc64″>
<jar href=”http://www.tylerburton.ca/swt/3.6.1/swt-gtk-linux-ppc64.jar” />
</resources>

<resources os=”Linux” arch=”x86_64″>
<jar href=”http://www.tylerburton.ca/swt/3.6.1/swt-gtk-linux-x86_64.jar” />
</resources>

<resources os=”Linux” arch=”amd64″>
<jar href=”http://www.tylerburton.ca/swt/3.6.1/swt-gtk-linux-x86_64.jar” />
</resources>

<resources os=”Linux” arch=”x86″>
<jar href=”http://www.tylerburton.ca/swt/3.6.1/swt-gtk-linux-x86.jar” />
</resources>

<resources os=”Linux” arch=”i386″>
<jar href=”http://www.tylerburton.ca/swt/3.6.1/swt-gtk-linux-x86.jar” />
</resources>

<resources os=”Linux” arch=”i686″>
<jar href=”http://www.tylerburton.ca/swt/3.6.1/swt-gtk-linux-x86.jar” />
</resources>

<resources os=”Mac” arch=”x86_64″>
<jar href=”http://www.tylerburton.ca/swt/3.6.1/swt-cocoa-mac-x86_64.jar” />
</resources>

<resources os=”Mac” arch=”amd64″>
<jar href=”http://www.tylerburton.ca/swt/3.6.1/swt-cocoa-mac-x86_64.jar” />
</resources>

<resources os=”Mac” arch=”x86″>
<jar href=”http://www.tylerburton.ca/swt/3.6.1/swt-cocoa-mac-x86.jar” />
</resources>

<resources os=”Mac” arch=”i386″>
<jar href=”http://www.tylerburton.ca/swt/3.6.1/swt-cocoa-mac-x86.jar” />
</resources>

<resources os=”Mac” arch=”i686″>
<jar href=”http://www.tylerburton.ca/swt/3.6.1/swt-cocoa-mac-x86.jar” />
</resources>

<resources os=”Mac”>
<jar href=”http://www.tylerburton.ca/swt/3.6.1/swt-carbon-mac.jar” />
</resources>

<resources os=”SunOS” arch=”sparc”>
<jar href=”http://www.tylerburton.ca/swt/3.6.1/swt-gtk-solaris-sparc.jar” />
</resources>

<resources os=”SunOS” arch=”x86″>
<jar href=”http://www.tylerburton.ca/swt/3.6.1/swt-gtk-solaris-x86.jar” />
</resources>

<application-desc main-class=”ca.tylerburton.hashverifier.HashVerifierMain” />

</jnlp>

As you can see I have outlined all of the platform configurations that I am going to be compatible with. Java Web Start takes care of the rest for me automatically.

Digital signatures

The final step is to digitally sign the executable jar. This is required because when deploying an application that is not sandboxed, or one that requires access to low-level functions and libraries (as is the case in SWT), the end user needs to know that the code they are receiving came directly from the source. The easiest way to do this is to follow the instructions here. Unfortunately unless you are willing to pay to have your certificate signed by a trusted certificate authority the end user will need to click OK through a big security warning before they can use your program. It’s a small issue to overcome but if Minecraft can do it without too much of a headache I’m sure you can too.

Easy deployment

It’s as simple as that. I didn’t have to re-write my code, heck I didn’t even have to adjust a single line and it all just works. To see the result on your platform click here.

Note: unfortunately there is an issue with the Mac version of Java Web Start & SWT that prevents it from working correctly. Until Apple fixes this, or OpenJDK takes over and does it, SWT applications cannot be started correctly on that platform through Web Start.

One thought on “Hash Verifier 0.3.0.1 (Java Web Start)

  1. Philipp Paland

    To start an SWT application on osx via webstart, you need something like

Comments are closed.