This guide is intended to help developers migrate their existing Java Plug-in applets to
Java Web Start applications. While it should be possible to migrate
most applets without problem, there are some considerations for developers to be aware of
when making the migration. The following guide describes details of the migration process.
Advantages of Migrating to Java Web Start Technology
Migrating provides the ability to target to a specific Java Runtime Environment (JRE) version
or a specific version range. Java Web Start technology supports multiple, simultaneous versions
of the Java Standard Edition platform. Specific applications can request specific Java versions
without conflicting with the different needs of other applications. Java Web Start technology
automatically downloads and installs the correct version of the Java platform as necessary,
based on the application's needs and the user's environment.
Another advantage is that users can launch a Java Web Start application independent of a Web browser.
A user can be off-line or unable to access the browser. Desktop shortcuts can also launch
the application, providing the user with the same experience as that of a native application.
Migrating an Existing Java Applet
Java Web Start technology has built-in support for applets. It is possible to run your applet
directly with Java Web Start technology without any re-compilation of the applet. All you need do
is to convert your applet HTML tags to a Java Network Launching Protocol (JNLP) file,
using the JNLP applet-desc element.
For example:
<resources>
<java version="1.5+"/>
<jar href="SwingSet2.jar"/>
</resources>
<applet-desc main-class="SwingSet2Applet" name="SwingSet" width="625" height="595">
<param name="param1" value="value1"/>
<param name="param2" value="value2"/>
</applet-desc>
Targeting to a Specific JRE
You can specify the targeted JRE versions using the java element and
it's version attribute. It supports the + and * operators,
and you can even list out the exact version.
Some examples follow:
|
Run with Java 5 or above:
|
<java version="1.5+"/>
|
|
Run with anything in the Java 5 family:
|
<java version="1.5*"/>
|
|
Run with Java 5 update 12 or above, or with Java 1.4.2 update 20 only:
|
<java version="1.5.0_12+ 1.4.2_20"/>
|
All your applet resources must be packaged inside a JAR (Java archive file), and have the
JAR file listed using the jar element.
The applet-desc element contains all the applet's information such as applet parameters,
width, height, etc. For more information regarding the applet-desc element,
refer to the JNLP specification, section 3.6.2, "Application descriptor for an Applet."
With the applet-desc tag, Java Web Start technology
uses it's own version of the applet viewer to start your applet.
By using the applet-desc tag, you can quickly migrate your applet to
Java Web Start technology.
However, your applet might not work properly if it has any dependency on the browser.
If time permits, it's best to re-write your Java applet as a Java application, and
launch it with Java Web Start technology.
Re-writing a Java Applet as a Java Web Start Application
The best way to migrate your applet is to re-write it as a standalone Java application, and
then deploy it with Java Web Start technology. Re-writing your applet and testing the resulting
application ensures that your converted applet works fully as expected. And your application
can take advantage of the Java Web Start features.
The re-write should be fairly straight forward. The major work needed is to convert your
applet class to the main class of the application.
The applet init and start methods are no longer present, instead,
you should initialize the application
at the beginning of the application's main method.
To quickly begin the migration, you can just add the main method to your original
applet class, and then start calling your applet initialization code
where it normally gets called from the applet's
init and start methods. Once there is a main method in the
applet class, you can begin launching it by means of Java Web Start technology,
and then slowly remove the dependency on the Applet class and convert it completely
to your application's main class.
For more information, refer to
JNLP File Syntax.
Special Considerations
Following is a list of considerations that may be important when migrating.
-
A Java Web Start application does not run within the web browser. So if your applet has any
dependency on the browser (for example, Java to JavaScript / JavaScript to Java communications
by means of the browser), the communication code will no longer work. The APIs that are
affected include:
-
JSObject API (netscape.javascript.JSObject.*) for Java to JavaScript
communication does not work for Java Web Start applications.
-
Common Document Object Model (DOM) API (
com.sun.java.browser.dom.* and
org.w3c.dom.*)
available for Java Plug-in applets are not available to Java Web Start applications.
-
Similar to Java Plug-in technology, Java Web Start technology will cache your application JARs
for faster start-up performance. However, resources downloaded by your own application code
will not be cached by Java Web Start technology.
-
Java Web Start technology provides permanent cookie support on Windows using the cookie store
in Internet Explorer, and the cookie-handling behavior is determined by the cookie control in IE.
On Linux/Solaris, Java Web Start technology provides permanent cookie support using its own
cookie store implementation. For more information, please refer to
Cookie Support
in the Java Deployment Guide.
-
If you deploy an applet with the JNLP
applet-desc element, your applet will be created
using the AppletContainer provided by Java Web Start technology. When your applet
calls Applet.getAppletContext(), it returns the AppletContainerContext
provided by Java Web Start technology. There are some minor differences in implementation between
the Java Plug-in AppletContext and the Java Web Start AppletContext.
The differences are:
-
The following Applet Persistence API methods are not implemented by Java Web Start technology.
AppletContext.getStream(String key)
AppletContext.getStreamKeys()
AppletContext.setStream(String key, InputStream s)
For Java Web Start applications, you can use the JNLP Persistence Service API for storing data
locally on the client's system. For more information, please refer to the
PersistenceService interface.
-
For
AppletContext.showDocument(URL url, String target),
the target argument will be ignored by Java Web Start technology.
-
For
AppletContext.showStatus(String status),
when launched with Java Web Start technology, this will set the JLabel text
that is below the applet, hosted by the Java Web Start AppletContainer.
-
Similar to
AppletContext.showDocument, Java Web Start applications are capabile
of showing an HTML page using the system's default web browser by using the
BasicService.showDocument API.
For a Java Plug-in applet:
AppletContext.showDocument(URL url)
AppletContext.showDocument(URL url, String target)
For a Java Web Start application:
BasicService.showDocument(URL url)
For more information refer to the
BasicService interface.
.
-
Following are considerations when retrieving resources from a JAR file.
In an applet, if you obtain a resource by means of these calls:
Applet.getImage(URL url)
Applet.getImage(URL url, String name)
Applet.getAudioClip(URL url)
Applet.getAudioClip(URL url, String name)
AppletContext.getAudioClip(URL url)
AppletContext.getImage(URL url)
Then in Java Web Start technology, the best practice is to include the resources in your application
JAR files, and access the resources using the JNLPClassLoader:
ClassLoader cl = this.getClass().getClassLoader();
URL url = cl.getResource(url);
Image im = Toolkit.getDefaultToolkit().createImage(url);
For more information, refer to
Retrieving Resources from JAR Files
in the Java Programmer's Reference Guide.
-
The pack200 JAR packing tool is supported by both the Java Web Start and the Java Plug-in
technologies.
If you are already deploying your applet JARs with pack200, no change should be needed when
migrating to Java Web Start technology.
For more information, refer to
Pack200 and Compression.
-
By using the
OBJECT tag in Java Plug-in technology, you can detect whether Java is
avaliable on the client's machine with the Plug-in CLSID and then auto-download
Java if necessary.
The same support is available with Java Web Start technology by using the Java Web Start
CLSID.
For more information, refer to
Creating the Web Page That Launches the Application
and
Auto-Install: Easier Launching of Java Web Start Applications
.
-
Following is information about HyperText Transfer Protocol Secure (HTTPS) support.
When using HTTPS from your own application code:
-
Java Web Start technology needs the JSSE (Java Secure Socket Extension) library for HTTPS support.
For Java 1.4 or above, JSSE is part of the Java core library. Thus applications deployed with
Java 1.4 or above have HTTPS support by default.
For Java 1.3 and prior JREs, if you want to use HTTPS, you will need to have the JSSE
extensions installed into the JRE lib\ext directory, or you will need to include the
JSSE library as part of your JNLP applications.
When using HTTPS inside the JNLP file for application JAR download:
-
If you deployed the Java extensions library using your Java Plug-in applets with the JAR manifests
approach
(
Deploying Java Extensions
),
it will no longer work with Java Web Start technology. An extensions library that already
exists in the JRE lib/ext directory will still be available to the Java Web Start application.
If you wish to deploy extensions for your Java Web Start application, you should use the
JNLP extension protocol mechanism. For more details, refer to the
JNLP specification, section 3.8 "Extension Descriptor."
One advantage of the JNLP extensions mechanism over Java Plug-in technology is that the
installed extensions will be available to all Java Web Start applications running on the system,
no matter what version of JRE the application is running with. While for Java Plug-in technology,
only applets running in the same JRE version can make use of the installed extensions.
-
For signed JAR files, similar to Java Plug-in technology, you can sign your application JAR files
and request your application to be run with all-permissions by means of the JNLP file.
In Java Plug-in technology, your applet JARs can be signed by different certificates.
In Java Web Start technology, the same certificate must be used to sign all JAR files
(
jar and nativelib elements) that are part of a single JNLP file.
This simplifies user management since only one certificate must be presented to the user
during a launch per JNLP file.
If you need to use JARs signed with different certificates, you can put them in a
component extension JNLP file, and reference it from the main JNLP file.
For more details, refer to the JNLP specification, section 5.4 "Signed Applications" and
section 4.7 "Extension Resources."
|