Build your first Webstart application
2005 Jean-Marc Autexier
IntroductionOne 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 applicationYour 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 fileYou 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 fileThe 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">
<homepage href="http://www.autexier.de/jmau" />
<description>A Java Webstart test</description>
<j2se version="1.4+" />
<jar href="JnlpTest.jar" />
<application-desc main-class="jnlptest.Main" />
Step 4: web server installationBoth 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:
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: testThat'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:
There are many more things you can configure in jnlp file (logo, several jar files, security, ...). Read the linsk below to get more information.
LinksDeveloper's Guide Java TM Web Start Technology Version 1.0.1
Unofficial 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