The JavaTM Tutorial
Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Trail: Deployment
Lesson: Java Web Start

Deploying Java Web Start Applications

This section describes the basics of deploying an application using Java Web Start. Deploying an application involves the following steps:
  1. Setting up the Web Server
  2. Creating the JNLP File
  3. Placing the Application on the Web Server
  4. Creating the Web Page
This section uses the Notepad example application to demonstrate Java Web Start technology. You can find all the source files for the Notepad application example in the \demo\plugin\jfc\Notepad directory within the JDK installation directory.

Setting up the Web Server

Before you can deploy an application with Java Web Start over the Web, you must ensure that the Web server you are using can handle JNLP files.

Configure the Web server so that files with the .jnlp extension are set to the application/x-java-jnlp-file MIME type.

How you set the JNLP MIME type depends on the Web server you are using. For example, for the Apache Web server, you simply add the line

application/x-java-jnlp-file JNLP
to the mime.types file.

For other Web servers, check the documentation for instructions on setting MIME types.

Creating the JNLP File

The key to running an application with Java Web Start is the Java Network Launching Protocol, or JNLP, file. The JNLP file is an XML file that contains elements and attributes that tell Java Web Start how to run the application.

An Example JNLP File

Following is the JNLP file for the Notepad demo:
<?xml version="1.0" encoding="utf-8"?>

<jnlp spec="1.0"
      codebase="http://javaweb.eng/~mh156787/tutorial/jar/jws/" 
      href="Notepad.jnlp">
   <information>
      <title>Notepad Demo</title>
      <vendor>Sun Microsystems, Inc.</vendor>
   </information>
   <resources>     
   	<jar href="Notepad.jar"/>   
	<j2se version="1.3+"
	      href="http://java.sun.com/products/autodl/j2se"/>
   </resources>
   <application-desc main-class="Notepad"/>
</jnlp>

If you
click this link to the Notepad.jnlp file, you open and run the Notepad application.

JNLP File Contents

The following table describes the elements and attributes in the sample JNLP file.

Note : This table does not include all possible contents of the JNLP file. For more information, see the Java Network Launching Protocol & API Specification (JSR-56)  (in the API reference documentation).

JNLP File Contents
Element Contents Description
jnlp spec
codebase
href
The spec attribute must be 1.0 or higher. The default is 1.0+. This attribute can typically be omitted.
The codebase attribute specifies the base location for all relative URLs specified in href attributes in the JNLP file.
The href specifies the URL of the JNLP file itself.
information title
vendor
The title element specifies the title of the application.
The vendor element specifies the provider of the application.
resources jar
j2se
The jar element contains the attribute href that specifies the JAR file that is part of the application's class path. The JAR file is loaded using a ClassLoader object. The JAR file typically contains classes that for the particular application, but can also contain other resources, such as icons and configuration files, that are available through the getResource mechanism.

The j2se element contains the attribute version that specifies the Java platform on which to run the application. The + symbol following the version signifies that the application can run on the specified version of the Java platform or a later version. The href attribute of the j2se element points to the URL from which the specified version of the Java platform can be automatically downloaded.

application-desc @main-class The application-desc element indicates that the JNLP file is to launch an application.
The main-class attribute specifies the entry point for the application; that is, the class that contains the public static void main(String[] args) method where execution begins. You can omit the main-class attribute if the first JAR file specified in the JNLP file contains a manifest file containing the main-class header.

Encoding JNLP Files

Java Web Start supports encoding of JNLP files in any character encoding supported by the Java platform. For more information on character encoding in Java, see the Supported Encodings Guide  (in the API reference documentation). To encode a JNLP file, specify an encoding in the XML prolog of that file. For example, the following line indicates that the JNLP file is encoded in UTF-16.
<?xml version="1.0" encoding="utf-16"?>

Note : The XML prolog itself must be UTF-8-encoded.

Placing the Application on the Web Server

The next step in deploying your application with Java Web Start is as simple as placing all the application's JAR files and the JNLP file on the Web server. You must ensure the JAR files are in the locations specified by the href attribute of the jar element in the JNLP file.

Creating the Web Page

Once you've completed to preceding steps, you are ready to write a Web page that gives users access to your application. Adding a link to your application in a Web page for users with Java Web Start already installed is simple; however, you must also design your Web page for users that might not have Java Web Start installed.

Adding the Basic Link to the JNLP File

In order to enable your users to launch the application from a Web page, you must include a link to the application's JNLP file from that Web page. To add this link, you use the standard HTML link syntax, with the href attribute specifying the location of the JNLP file:
<a href="Notepad.jnlp">Launch Notepad Application</a>
Assuming Java Web Start is installed on the client computer, when the user clicks this link, Java Web Start executes the application based on the instructions in the JNLP file.

Adding the Link when Java Web Start is not Installed

For users who might not have Java Web Start installed, you must write scripts in your Web page to:
  1. Detect which browser the user has.
  2. Detect whether Java Web Start is installed.
  3. If Java Web Start is not installed, either auto-install it, or direct the user to a download page.
For more information and sample scripts to use for these steps, see the
Java Web Start Guide  (in the API reference documentation).

Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Copyright 1995-2005 Sun Microsystems, Inc. All rights reserved.