Creating a JNLP in Java

Hi All,

Java Web Start (also known as JavaWS or javaws) is a framework developed by Sun Microsystems that allows users to start application software for the Java Platform directly from the Internet using a web browser.

JNLP Stands for Java Network Launching Protocol (JNLP)

Follow the below steps to Create a Test JNLP Example.

Step 1: Install JDk and Tomcat 6.0 (ignore if already setup)

Step 2:
Create the directory structure. e.g c:\myTestJNLP

Step3 :
Create a java class JNLPExample.

package com.test.jnlp;
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class JNLPExample {

public static void main(String args[]) {
JFrame frame = new JFrame(“ROCKSOLUTIONS Frame”);

Container content = frame.getContentPane();
content.add(label, BorderLayout.CENTER);
String message = “Welcome to JNLP”;
JLabel label = new JLabel();


Step 4:
Export to a JAR File(if using Eclipse) or create a Jar file
e.g   jar -cf   JnlpExample.jar *.*

Step 5:
Create a .keystore file.
e.g   keytool -genkey -keystore myKeys -alias jdc

Step 6:
Assign keystore to the JAR File using jarsigner utility
e.g    jarsigner -keystore myKeys  JnlpExample.jar  jdc

Step 7:
Now Deploy the jar into the server(for this example Tomcat 6 has been used)
For deploying simply copy the Jar file into the Root Applcation of the Tomcat.
e.g  Tomcat 6.0\webapps\root\JNLPExample.jar

Step 8:
Now create a JNLP file.

xml version=”1.0″ encoding=”utf-8″?>
<jnlp spec=”1.0+” codebase=”http://localhost:8070/&#8221; href=”JNLPExample.jnlp”>
<span class=”hiddenSpellError” pre=””>Jnlp</span> Testing
<homepage href=”http://localhost:8070/&#8221; />
<description>Any description</description>
<j2se version=”1.6+” />
<jar href=”JnlpExample.jar” />
<application-desc main-class=”com.test.jnlp.JNLPExample” />

Step 9:
After creating the JNLP, copy the JNLP file into the same location where jar has been copied into the Tomcat root folder.

Step 10:
Ignore if not required, as we are going to invoke the JNLP from tomcat server, it’s better to add the Mime type in web.xml so that request could be properly served by the server.


Step 11:
Access the JNLP File, URL http://localhost:8070/JNLPExample.jnlp, download and double-click on it to run, You will see a Java Web start pop up on the screen and asking for your confirmation to run the file.

Hope this helps.

R Vashi.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

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

Google photo

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

Twitter picture

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

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.