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”);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

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

frame.pack();
frame.show();
}
}


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”>
<information>
<span class=”hiddenSpellError” pre=””>Jnlp</span> Testing
<vendor>RockSolutions</vendor>
<homepage href=”http://localhost:8070/&#8221; />
<description>Any description</description>
</information>
<security>
<all-permissions/>
</security>
<resources>
<j2se version=”1.6+” />
<jar href=”JnlpExample.jar” />
</resources>
<application-desc main-class=”com.test.jnlp.JNLPExample” />
</jnlp>


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.

<mime-mapping>
<extension>jnlp</extension>
<mime-type>application/x-java-jnlp-file</mime-type>
</mime-mapping>


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.


Thanks
R Vashi.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s