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 Java Web Start (Jnlp) Tutorial - UnOfficial Guide will guide you to do following
1) Create a simple AWT program and jar it as TestJnlp.jar
2) Add keystroke into TestJnlp.jar
3) Create a Jnlp file
4) Put all into Tomcat Folder
5) Access TestJnlp.jar from web through http://localhost:8080/Test.Jnlp
1) Install Java JDK/JRE version above 1.5 and Tomcat
2) Create a simple Java AWT program, file structure as picture below

AWT Source code
package com.mkyong; import java.awt.*; import javax.swing.*; import java.net.*; import javax.jnlp.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class TestJnlp { static BasicService basicService = null; public static void main(String args[]) { JFrame frame = new JFrame("Mkyong Jnlp UnOfficial Guide"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label = new JLabel(); Container content = frame.getContentPane(); content.add(label, BorderLayout.CENTER); String message = "Jnln 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://www.mkyong.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(); } }
P.S If “import javax.jnlp.*;” not found, please include jnlp library which located at JRE/lib/javaws.jar.
3) Jar It , located to java class file folder and issue following command in command prompt
jar -cf TestJnlp.jar *.*
4) Same location, Add keystroke name “testkeys”
keytool -genkey -keystore testKeys -alias jdc
It will ask for keystroke password, first name, last name , organization’s unit…etc..just fill them all.
5) Same location, Attached newly keystroke “testkeys” to TestJnlp.jar file
jarsigner -keystore testKeys TestJnlp.jar jdc
It will ask password for your newly created keystroke
6) Copy TestJnlp.jar to tomcat default web server folder.
C:\Program Files\Apache\Tomcat 6.0\webapps\ROOT
7) Create Test.jnlp file to execute TestJnlp.jar.
<?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.mkyong.TestJnlp" /> </jnlp>
Configuration is quite simple, please change accordingly.
8 ) Copy Test.jnlp to tomcat default web server folder also.
C:\Program Files\Apache\Tomcat 6.0\webapps\ROOT
9) Start Tomcat
C:\Tomcat folder\bin\tomcat6.exe
P.S Latest Tomcat like version 6, it already configure jnlp in web.xml properly. If jnlp is not response, please add following statement in your web.xml which located in tomcat conf folder.
<mime-mapping> <extension>jnlp</extension> <mime-type>application/x-java-jnlp-file</mime-type> </mime-mapping>
10) Access URL http://localhost:8080/Test.jnlp, download Test.jnlp and double click on it
11) It will run as following if everything go fine
11) If you want to execute it again, just double click on Test.jnlp that you downloaded just now, it is no need to visit http://localhost:8080/Test.jnlp again
12) Done


(2 votes, average: 8.5 out of 10)
















No comments yet.