Creating a Java WebStart (JNLP) application

Java WebStart, also called Java Network Launching Protocol (JNLP), allows you to launch Java applications directly from the internet using a webbrowser. In this article we will create a simple application and all configuration files necessary to launch it through Java WebStart.

We start with a simple Java program with a GUI:

package nl.jansipke.samplegui;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class SampleGUI extends JFrame {

    private static final long serialVersionUID = 522159447010444143L;

    public SampleGUI() {
        setTitle("Sample GUI");
        setSize(300, 200);

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                SampleGUI sampleGUI = new SampleGUI();

Java WebStart applications run in a sandbox with very limited default capabilities. The application can ask for extra permissions in the JNLP file, as can be seen in the following file.

<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+" codebase="" href="SampleGUI.jnlp">

        <vendor>Some Vendor Name</vendor>
        <homepage href=""/>
        <description>SampleGUI description</description>


        <j2se version="1.6+"/>
        <jar href="SampleGUI.jar"/>

    <application-desc main-class="nl.jansipke.samplegui.SampleGUI"/>


The JAR file needs to be signed for these permissions to take effect. We need to create a keystore file for that first. If needed you may change the alias and the keystore file name.

keytool -genkey -alias alias -keystore keystore.bin

Answer the questions the keytool command asks and copy the file into a directory where the following ANT build script can find it:

<?xml version="1.0" encoding="UTF-8"?>
<project name="samplegui" basedir=".">

    <property name="" value="bin" />
    <property name="dir.dist" value="dist" />
    <property name="dir.src" value="src" />
    <property name="file.jar" value="SampleGUI.jar" />

    <path id="compile.classpath">
        <fileset dir=".">
            <include name="lib/*.jar" />

    <target name="clean" description="Clean project">
        <delete dir="${}" />

    <target name="prepare" description="Prepare project">
        <mkdir dir="${}" />

    <target name="compile" description="Compile project" depends="prepare">
        <javac destdir="${}" classpathref="compile.classpath" debug="true" includeantruntime="false">
            <src path="${dir.src}" />

    <target name="jar" description="Build jar file" depends="compile">
        <mkdir dir="${dir.dist}" />
        <jar destfile="${dir.dist}/${file.jar}" basedir="${}">
                <attribute name="Main-Class" value="nl.jansipke.samplegui.SampleGUI"/>

    <target name="signjar" description="Sign jar file" depends="jar">
        <signjar jar="${dir.dist}/${file.jar}" alias="alias" storepass="secret" keystore="keystore.bin"/>


Now run the ANT script (target signjar) and copy the resulting JAR file and the JNLP file to a directory on your webserver. Fire up a webbrowser and point it to the JNLP file. If all goes well, it will present you with a warning about permissions. Check yes and it will start the application.

This entry was posted in programming and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s