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 keystore 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
Tutorial
1. Install JDk and Tomcat
Install Java JDK/JRE version above 1.5 and Tomcat.2. Create AWT file and file structure
Create file structure as followingTestJnlp.java
Create a new Java file, and put into the specified folder location, see above picture.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.rgcollege.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();
}
}
3. Jar It
Located the Java's classes file folder and issue following command in command promptjar -cf TestJnlp.jar *.*
4. Create keystore
Add a new keystore named "testkeys"keytool -genkey -keystore testKeys -alias jdc
5. Assign keystore to Jar file
Attached newly keystore "testkeys" to TestJnlp.jar filejarsigner -keystore testKeys TestJnlp.jar jdc
6. Deploy JAR it
Copy TestJnlp.jar to Tomcat's default web server folder.C:\Program Files\Apache\Tomcat 6.0\webapps\ROOT
7. Create JNLP file
Create a new Test.jnlp file in order 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>
8. Deploy JNLP file
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
<mime-mapping>
<extension>jnlp</extension>
<mime-type>application/x-java-jnlp-file</mime-type>
</mime-mapping>
No comments:
Post a Comment