Java
Java SE
| JDK Documentation |
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 + 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.
applet-descThe 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 .
Following is a list of considerations that may be important when migrating.
JSObject API ( netscape.javascript.JSObject.*) for Java to JavaScript communication does not work for Java Web Start applications.
com.sun.java.browser.dom.* and org.w3c.dom.*) available for Java Plug-in applets are not available to Java Web Start applications.
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:
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.
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 JLabel text that is below the applet, hosted by the Java Web Start AppletContainer.
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)
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.
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 .
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.
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."