Java Web Start (Jnlp) Tutorial | Code Factory

Reference Link : Link

Here is a brief explanation about Java Web Start from SUN

Java Web Start is a mechanism for program delivery through a standard Web server. Typically initiated through the browser, these programs are deployed to the client and executed outside the scope of the browser. Once deployed, the programs do not need to be downloaded again, and they can automatically download updates on startup without requiring the user to go through the whole installation process again.

This tutorial shows you how to create a Java Web Start (Jnlp) file for user to download, when user click on the downloaded jnlp file, launch a simple AWT program.

Step 01 : Directory Structure

Step 02 : Create file

package com.codeFactory;import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.jnlp.BasicService;
import javax.jnlp.ServiceManager;
import javax.jnlp.UnavailableServiceException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Test {
static BasicService basicService = null;
public static void main(String args[]) {
JFrame frame = new JFrame("Code Factory");
JLabel label = new JLabel();
Container content = frame.getContentPane();
content.add(label, BorderLayout.CENTER);
String message = "Jnlp Hello Word";
label.setText(message);try {
basicService = (BasicService) ServiceManager.lookup("javax.jnlp.BasicService");
} catch (UnavailableServiceException e) {
System.err.println("Lookup failed: " + e);
JButton button = new JButton("");ActionListener listener = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
try {
URL url = new URL(actionEvent.getActionCommand());
} catch (MalformedURLException ignored) {
button.addActionListener(listener);content.add(button, BorderLayout.SOUTH);

Step 03 : Right click on project and Export jar

Step 04 : Open CMD with folder where you save the jar and run below command

keytool -genkey -keystore testKeys -alias jdc

Step 05 : Assign keystore to jar file

jarsigner -keystore testKeys TestJnlp.jar jdc

Step 06 : Deploy Jar

Copy Test.jar in <tomcat> > webapps > ROOT folder

Step 07 : create Test.jnlp and copy below code

<?xml version="1.0" encoding="utf-8"?> 
<jnlp spec="1.0+" codebase="http://localhost:8080/" href="Test.jnlp">
<title>Jnlp Testing</title>
<vendor>YONG MOOK KIM</vendor>
<homepage href="http://localhost:8080/" />
<description>Testing Testing</description>
<j2se version="1.6+" />
<jar href="TestJnlp.jar" />
<application-desc main-class="com.codeFactory.Test" />

Step 08 : copy Test.jnlp file in <tomcat> > webapps > ROOT folder

Step 09 : start Tomcat

Step 10 : open URL https://localhost:8080/Test.jnlp, it will prompt you to download the Test.jnlp file, just accept and double click on it.

Step 11 : double click on downloaded Test.jnlp

Step 12 : If everything fine then you will get result of Step : 15 Otherwise you will get below Error

Step 13 : open Control Panel and click on Java then click on Security tab

Step 14 : again double click on downloaded Test.jnlp

Step 15 : click on Run

Reference Link :



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store