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.
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.
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>
You can specify the targeted JRE versions using the
java element and it's version attribute. It supports the
* operators, and you can even list out the exact version. Some examples follow:
|Run with Java 5 or above:||
|Run with anything in the Java 5 family:||
|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
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."
applet-desc tag, Java Web Start technology uses it's own version of the applet viewer to start your applet.
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
start methods are no longer present, instead, you should initialize the application at the beginning of the application's
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
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
Following is a list of considerations that may be important when migrating.
org.w3c.dom.*) available for Java Plug-in applets are not available to Java Web Start applications.
applet-descelement, your applet will be created using the
AppletContainerprovided by Java Web Start technology. When your applet calls
Applet.getAppletContext(), it returns the
AppletContainerContextprovided by Java Web Start technology. There are some minor differences in implementation between the Java Plug-in
AppletContextand the Java Web Start
AppletContext. The differences are:
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
AppletContext.showDocument(URL url, String target), the target argument will be ignored by Java Web Start technology.
AppletContext.showStatus(String status), when launched with Java Web Start technology, this will set the
JLabeltext that is below the applet, hosted by the Java Web Start
AppletContext.showDocument, Java Web Start applications are capabile of showing an HTML page using the system's default web browser by using the
For a Java Plug-in applet:
AppletContext.showDocument(URL url) AppletContext.showDocument(URL url, String target)
For a Java Web Start application:
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
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.
OBJECTtag in Java Plug-in technology, you can detect whether Java is avaliable on the client's machine with the Plug-in
CLSIDand 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 .
When using HTTPS from your own application code:
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 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.
nativelibelements) 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."