Migrating Java Applets to Java Web Start Applications

Java Rich Internet Applications Guide > Migrating Java Applets to Java Web Start Applications

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.

The following topics are covered:

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 its version attribute. It supports the + and * operators, and you can even list out the exact version. Some examples follow:

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 its own version of the applet viewer to start your applet.

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.


Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.