The file should download and show up in your download bar at the bottom of the screen. Click the down arrow next to the JNLP file and click “Always open files of this type.”.
Join the DZone community and get the full member experience.
Join For FreeThis tutorial shows you how to create a Java Web Start (Jnlp) file for user download. When the user clicks on the downloaded jnlp file, it launches a simple AWT program. Here's the summary steps :
- Create a simple AWT program and jar it as TestJnlp.jar
- Add keystore into TestJnlp.jar
- Create a Jnlp file
- Put it all into the Tomcat Folder
- Access TestJnlp.jar from web through http://localhost:8080/Test.Jnlp
Before starting this tutorial, lets read this brief Java Web Start explanation from Oracle.
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.
Ok, let's go ~
1. Install JDk and Tomcat
Install Java JDK/JRE version above 1.5 and Tomcat.
2. Directory Structure
Directory structure of this example.
3. AWT + JNLP
See the content of TestJnlp.java, it's just a simple AWT program with jnlp supported.
P.S If 'import javax.jnlp.*;' is not found, please include the jnlp library which islocated at JRE/lib/javaws.jar.
4. Jar It
Located your Java classes folder. Jar it with following command in command prompt
This will package all the Java's classes into a new jar file, named 'TestJnlp.jar'.
5. Create keystore
Add a new keystore named 'testkeys'
It will ask for a keystore password, first name, last name , organization's unit...etc..just fill them all.
6. Assign keystore to Jar file
Attached newly generated keystore 'testkeys' to your 'TestJnlp.jar' file
It will ask password for your newly created keystore
7. Deploy JAR it
Copy 'TestJnlp.jar' to Tomcat's default web server folder, for example, in Widnows - C:Program FilesApacheTomcat 6.0webappsROOT
8. Create JNLP file
Create a new Test.jnlp file, content put this
9. Deploy JNLP file
Copy Test.jnlp to your Tomcat default web server folder also. C:Program FilesApacheTomcat 6.0webappsROOT
10. Start Tomcat
Start Tomcat , C:Tomcat folderbintomcat6.exe
11. Test it
Access URL http://localhost:8080/Test.jnlp, it will prompt you to download the Test.jnlp file, just accept and double click on it.
If everything went fine, you should see the following output
Click on the 'Run' button to lauch the AWT program.
Note
If jnlp has no response, put the following code in your web.xml, which is located in the Tomcat conf folder.
Like This Article? Read More From DZone
Opinions expressed by DZone contributors are their own.