Java applets have been a deprecated technology for a while. It has become increasingly difficult to run Java applets in modern browsers. Browser vendors are phasing out support for browser plugins based on the Netscape Plugin API (NPAPI) such as the Java plugin, which is required to run applets in the browser. Microsoft Edge and Google Chrome already have stopped supporting NPAPI plugins, Mozilla Firefox will stop supporting it at the end of 2016. This effectively means that Java applets will be dead by the end of the year.
However, it does not necessarily mean that Java applet based projects and code bases, which can’t be easily rewritten to use other technologies such as HTML5, have to become useless. Oracle recommends the migration of Java applets to Java Web Start applications. This is a viable option if the application is not required to be run embedded within a web page.
To convert an applet to a standalone Web Start application you put the applet’s content into a frame and call the code of the former applet’s init() and start() from the main() method of the main class.
Java Web Start applications are launched via the Java Network Launching Protocol (JNLP). This involves the deployment of an XML file on the web server with a “.jnlp” file extension and content type “application/x-java-jnlp-file”. This file can be linked on a web page and looks like this:
<?xml version="1.0" encoding="UTF-8"?> <jnlp spec="1.0+" codebase="http://example.org/demo/" href="demoproject.jnlp"> <information> <title>Webstart Demo Project</title> <vendor>Softwareschneiderei GmbH</vendor> <homepage>http://www.softwareschneiderei.de</homepage> <offline-allowed/> </information> <resources> <j2se version="1.7+" href="http://java.sun.com/products/autodl/j2se"/> <jar href="demo-project.jar" main="true"/> <jar href="additional.jar"/> </resources> <application-desc name="My Project" main-class="com.schneide.demo.WebStartMain"> </application-desc> <security> <all-permissions/> </security> <update check="always"/> </jnlp>
The JNLP file describes among other things the required dependencies such as the JAR files in the resources block, the main class and the security permissions.
The JAR files must be placed relative to the URL of the “codebase” attribute. If the application requires all permissions like in the example above, all JAR files listed in the resources block must be signed with a certificate.
<script src="https://www.java.com/js/deployJava.js"></script> <script> deployJava.launchButtonPNG = 'http://example.org/demo/launch.png'; deployJava.createWebStartLaunchButton('http://example.org/demo/demoproject.jnlp', '1.7.0'); </script>
The Java applet technology has now reached its “end of life”, but valuable applet-based projects can be saved with relatively little effort by converting them to Web Start applications.