Java Web Start (JNLP)

Java Web Start is a mechanism for program delivery through a standard web server. The Java application is downloaded to the client and executed outside the web browser (unlike applets). The application does not need to be downloaded again on next run. If the application is updated, a new version will be downloaded automatically.

JNLP (Java Network Launching Protocol) is defined with XML schema and specifies the resources needed to run Java Web Start applications. JNLP file (.jnlp) defines the URL location of the jar file, declares the main method, VM arguments and other resources that JRE on the client side should know to start Java Web Start application. The Java Web Start application can be started by double-clicking on the .jnlp file.

In this tutorial we will deploy JWS application with basic deployment descriptor (minimum requirements) and more advanced deployment which includes creating a keystore and signing jar file.

To start with JWS we need an application packed in jar file that will be running on the client's host. Swing application seems the most appropriate choice.

I assume you know how to write a Swing application and build jar file, so I will just skip this step. All you need is a class with main method that displays a Swing GUI packed in jar file.

Basic example

Basic deployment descriptor specifies minimum of required arguments that are needed to start JWS application.
<information> element provides some description of your JWS application,
<resources> element provides URL location of jar files (codebase+jar href) and minimum JRE version, and
<application-desc> element defines the main-class.

<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+" codebase=""
<vendor>Matjaz Cerkvenik</vendor>
<homepage href="" />
<description>Convert ms to Date</description>
<j2se version="1.5+" />
<jar href="timetest.jar" />
<application-desc main-class="my.project.jnlp.TimeTest" />

Deploy and run

Save the xml above in file timetest.jnlp (or whatever name you prefer) and upload it to the web server on the exact URL as defined in codebase attribute. This is the root directory of JWS application. In the same directory upload the jar files.

Enter the address of jnlp file in web browser and hit enter. The jnlp file is downloaded and the JWS application should start automatically. If not, double click on the .jnlp file. Try the following example:

Advanced example - Signing the jar

Advanced Java applications that need access to system resources, like file system, network connections etc... need to be signed - generate a keystore (certificate) and attach it to the jar file.

Create a keystore:

$ keytool -genkey -keystore timetestKeys -alias mykey

Enter the password for generated keystore and fill the other data.

Apply keystore to jar:

$ jarsigner -keystore timetestKeys timetest.jar mykey

You will be asked to enter password for keystore (from previous step).

The following jnlp descriptor contains much more elements and attributes. The most remarkable are:
<icon> defines an icon of desktop application
<security> specifies that the application will use system resources and therefore must be signed
<argument> java arguments

<?xml version="1.0" encoding="utf-8"?>
<title>TimeTest Application</title>
<vendor>Matjaz Cerkvenik</vendor>
<homepage href="docs/about.html"/>
<description>Convert milliseconds to date</description>
<description kind="short">Convert ms to Date</description>
<icon href="Clock-icon.png"/>
<icon kind="splash" href="Clock-icon.png"/>
<association mime-type="application-x/timetest-file" extensions="timetest" />
<shortcut online="false">
<menu submenu="My Apps"/>
<information os="linux">
<title>TimeTest on Linux</title>
<homepage href="docs/about.html" />
<j2se version="1.4.2+" java-vm-args="-esa -Xnoclassgc"/>
<jar href="timetest.jar"/>
<application-desc main-class="my.project.jnlp.TimeTest">