|
|
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\Notepaddirectory 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
.jnlpextension are set to theapplication/x-java-jnlp-fileMIME 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.typesfile.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 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>Notepad.jnlpfile, 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 jnlpspec
codebase
hrefThe specattribute must be1.0or higher. The default is1.0+. This attribute can typically be omitted.
Thecodebaseattribute specifies the base location for all relative URLs specified inhrefattributes in the JNLP file.
Thehrefspecifies the URL of the JNLP file itself.informationtitle
vendorThe titleelement specifies the title of the application.
Thevendorelement specifies the provider of the application.resourcesjar
j2seThe jarelement contains the attributehrefthat specifies the JAR file that is part of the application's class path. The JAR file is loaded using aClassLoaderobject. 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 thegetResourcemechanism.The
j2seelement contains the attributeversionthat 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. Thehrefattribute of thej2seelement points to the URL from which the specified version of the Java platform can be automatically downloaded.application-desc@main-classThe application-descelement indicates that the JNLP file is to launch an application.
Themain-classattribute 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-classattribute if the first JAR file specified in the JNLP file contains a manifest file containing themain-classheader.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 thehrefattribute of thejarelement 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 thehrefattribute 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.