Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
This section describes the basics of deploying an application using Java Web Start. Deploying an application involves the following steps: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
- Setting up the Web Server
- Creating the JNLP File
- Placing the Application on the Web Server
- Creating the Web Page
\demo\plugin\jfc\Notepad
directory within the JDK installation directory.
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 theapplication/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
to theapplication/x-java-jnlp-file JNLPmime.types
file.For other Web servers, check the documentation for instructions on setting MIME types.
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:If you click this link to the<?xml version="1.0" encoding="utf-8"?> <!-- JNLP File for Notepad --> <jnlp spec="1.0+" codebase="http://java.sun.com/docs/books/tutorialJWS/deployment/webstart/ex5/" href="Notepad.jnlp"> <information> <title>Notepad Demo</title> <vendor>The Java(tm) Tutorial: Sun Microsystems, Inc.</vendor> <description>Notepad Demo</description> <homepage href="http://java.sun.com/docs/books/tutorial/deployment/webstart/running.html"/> <description kind="short">ClickMeApp uses 3 custom classes plus several standard ones</description> <offline-allowed/> </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>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).
JNLP File Contents Element Contents Description jnlp
spec
codebase
hrefThe spec
attribute must be1.0
or higher. The default is1.0+
. This attribute can typically be omitted.
Thecodebase
attribute specifies the base location for all relative URLs specified inhref
attributes in the JNLP file.
Thehref
specifies the URL of the JNLP file itself.information
title
vendorThe title
element specifies the title of the application.
Thevendor
element specifies the provider of the application.resources
jar
j2seThe jar
element contains the attributehref
that specifies the JAR file that is part of the application's class path. The JAR file is loaded using aClassLoader
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 thegetResource
mechanism.The
j2se
element contains the attributeversion
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. Thehref
attribute of thej2se
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.
Themain-class
attribute specifies the entry point for the application; that is, the class that contains thepublic static void main(String[] args)
method where execution begins. You can omit themain-class
attribute if the first JAR file specified in the JNLP file contains a manifest file containing themain-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. 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.
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 thehref
attribute of thejar
element in the JNLP file.
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 thehref
attribute specifying the location of the JNLP file: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.<a href="Notepad.jnlp">Launch Notepad Application</a>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:For more information and sample scripts to use for these steps, see the Java Web Start Guide.
- Detect which browser the user has.
- Detect whether Java Web Start is installed.
- If Java Web Start is not installed, either auto-install it, or direct the user to a download page.
Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
Copyright 1995-2005 Sun Microsystems, Inc. All rights reserved.