Build your first Webstart application
2005 Jean-Marc Autexier
Introduction
One of the main advantage of Java is portability. Another key feature is the deployment mechanism of standalone Java software applications. WebStart allows to start an application with a single click over the network, ensuring the deployment of the latest version and offline functionality.This tutorial shows how easy it is to deploy your application with Java Webstart.
Step 1: build your application
Your application must be available as a jar file. We will use here a small desktop application which only display "Hello WebStart" in a JFrame. You can use your favorite IDE to build and package your own application, or just download my jar-file.Step 2: sign the jar file
You must sign the jar file in order that people can verify it's origin (an decide if they trust the application or not). The JDK contains a tool which allows signing of jar file with a certificate. If you don't have your own certificate, you can use the tool also to build one.Create new certificate:
keytool -genkey -keystore yourKeystore -alias YourNameYou will be prompted several questions. At the end, your personal certificate will be in your keystore "yourKeystore". You can check it by calling
keytool -list -keystore yourKeystoreNow you can sign the jar file:
jarsigner -keystore yourKeystore test.jar YourNameThat's it. The jar file includes know your signature and people can decide if they trust it.
Step 3: jnlp file
The jnlp (Java Network Launching Protocol) file describes mainly which file are included in the application (only one jar file in our case), which is the main class, which JRE version to use and the network location (used for update checks).Here is our Webstart.jnlp file:
<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+" codebase="http://www.autexier.de/jmau/dev/webstart" href="webstart.jnlp">
<information>
<title>WebStart Demo</title>
<vendor>Jean-Marc Autexier</vendor>
<homepage href="http://www.autexier.de/jmau" />
<description>A Java Webstart test</description>
<offline-allowed />
</information>
<resources>
<j2se version="1.4+" />
<jar href="JnlpTest.jar" />
</resources>
<security>
<all-permissions />
</security>
<application-desc main-class="jnlptest.Main" />
</jnlp>
Step 4: web server installation
Both the jar and the jnlp file must be available on a http server. The web server must return a special MIME type for JNLP files:application/x-java-jnlp-file
If you have an apache webserver, the easiest way is to place a .htaccess file in the same directory than the application.
AddType application/x-java-jnlp-file .jnlp
AddType application/x-java-archive-diff .jardiff
Step 5: test
That's it. Now when you call the Url of the jnlp file and your browser is configured correctly, java webstart client will open, download the application, ask for security reasons if you trust the certificate owner and execute it.Try it out:
Links
Developer's Guide Java TM Web Start Technology Version 1.0.1Unofficial Java Web Start/JNLP FAQ
Sun WebStart Demo
Joshua Marinacci: Java Sketchbook: Getting Started with Java Web Start: add an icon, add a splash screen
(c) Jean-Marc Autexier, August 2005
