DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Introducing Graph Concepts in Java With Eclipse JNoSQL, Part 3: Understanding Janus
  • Introducing Graph Concepts in Java With Eclipse JNoSQL, Part 2: Understanding Neo4j
  • How to Introduce a New API Quickly Using Micronaut
  • Introducing Graph Concepts in Java With Eclipse JNoSQL

Trending

  • Event Driven Architecture (EDA) - Optimizer or Complicator
  • Monolith: The Good, The Bad and The Ugly
  • How to Create a Successful API Ecosystem
  • Event-Driven Microservices: How Kafka and RabbitMQ Power Scalable Systems
  1. DZone
  2. Coding
  3. Java
  4. Java Web Start (Jnlp) Hello World Example

Java Web Start (Jnlp) Hello World Example

By 
Yong Mook Kim user avatar
Yong Mook Kim
·
Nov. 16, 10 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
93.8K Views

Join the DZone community and get the full member experience.

Join For Free

this 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 :

  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 it all into the tomcat folder
  5. 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.

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.*;" 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

jar -cf testjnlp.jar *.*

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 "

keytool -genkey -keystore testkeys -alias jdc

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

jarsigner -keystore testkeys testjnlp.jar jdc

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 files\apache\tomcat 6.0\webapps\root

8. create jnlp file

create a new test.jnlp file, content put this

<?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>

9. deploy jnlp file

copy test.jnlp to your tomcat default web server folder also. c:\program files\apache\tomcat 6.0\webapps\root

10. start tomcat

start tomcat , c:\tomcat folder\bin\tomcat6.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.

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

Java Web Start Java (programming language)

Opinions expressed by DZone contributors are their own.

Related

  • Introducing Graph Concepts in Java With Eclipse JNoSQL, Part 3: Understanding Janus
  • Introducing Graph Concepts in Java With Eclipse JNoSQL, Part 2: Understanding Neo4j
  • How to Introduce a New API Quickly Using Micronaut
  • Introducing Graph Concepts in Java With Eclipse JNoSQL

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!