Migrating Java Applets to Java Web Start and JNLP

< Contents

Migrating Java Applets to Java Web Start and JNLP

Because browsers are reducing or eliminating support for the Java Plug-in, consider migrating existing Java applets to Java Web Start, which uses the Java Network Launching Protocol (JNLP) to download and run an application locally.

Although available and supported in JDK 8, the Applet API and the Java Plug-in are marked as deprecated in preparation for removal in a future release. Alternatives for applets and embedded JavaFX applications include Java Web Start and self-contained applications.

Migrating to Java Web Start provides the ability to launch the application independent of a web browser. When your user is offline or unable to access the browser, a desktop shortcut can launch the application, providing your user with the same experience as that of a native application.

This chapter includes the following topics:

Migrating an Existing Java Applet

Java Web Start technology has built-in support for applets. Your applet can run with Java Web Start technology without any recompilation of the applet. Just convert your applet HTML tags to a Java Network Launching Protocol (JNLP) file using the JNLP applet-desc element, for example:

<resources>
  <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>

Note: Although available and supported in JDK 8, the Applet API is marked as deprecated in preparation for removal in a future release. Instead of applets, consider alternatives such as Java Web Start or self-contained applications.

Rewriting a Java Applet as a Java Web Start Application

The best way to migrate your applet is to rewrite it as a standalone Java application, and then deploy it with Java Web Start technology. Rewriting your applet and testing the resulting application ensures that your converted applet works as expected, and your application can take advantage of the Java Web Start features.

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, initialize the application at the beginning of the application's main method.

To quickly begin the migration, 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. When there is a main method in the applet class, you can begin launching it by using the Java Web Start technology, and then slowly remove the dependency on the Applet class and convert it completely to your application's main class.

Special Considerations

The following items are things to consider when migrating:


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