Java Web Start (Jnlp) Tutorial | Code Factory
Reference Link : Link
Donate : PayPal
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 Test.java
file
package com.codeFactory;import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.MalformedURLException;
import java.net.URL;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");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
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("http://34codefactory.wordpress.com");ActionListener listener = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
try {
URL url = new URL(actionEvent.getActionCommand());
basicService.showDocument(url);
} catch (MalformedURLException ignored) {
}
}
};button.addActionListener(listener);content.add(button, BorderLayout.SOUTH);
frame.pack();
frame.show();
}
}
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">
<information>
<title>Jnlp Testing</title>
<vendor>YONG MOOK KIM</vendor>
<homepage href="http://localhost:8080/" />
<description>Testing Testing</description>
</information>
<security>
<all-permissions/>
</security>
<resources>
<j2se version="1.6+" />
<jar href="TestJnlp.jar" />
</resources>
<application-desc main-class="com.codeFactory.Test" />
</jnlp>
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 :