When applets are deployed by using the Java Network Launch Protocol (JNLP), the Java Plug-in software launches the applet after downloading the JNLP file from the network. Beginning in the Java SE 7 release, you can reduce the the time it takes for applets to launch, by embedding the JNLP file in the web page itself so that an additional network request can be avoided the first time the applet is loaded. This will result in applets launching quickly on the web browser.
A Base64 encoded JNLP file can be embedded in the jnlp_embedded
parameter when deploying an applet in a web page. The attributes of the <jnlp>
element should meet the following restrictions:
href
attribute should contain a relative path.codebase
attribute should not be specified. This implies that the codebase will be derived from the URL of the web page in which the applet is loaded.The following steps describe how to embed a JNLP file in a web page to deploy an applet.
JNLP
file for your applet. A sample file is shown next.
<?xml version="1.0" encoding="UTF-8"?> <!-- href attribute contains relative path; codebase attribute not specified --> <jnlp href="dynamictree_applet.jnlp"> <information> <title>Dynamic Tree Demo</title> <vendor>Dynamic Team</vendor> </information> <resources> <!-- Application Resources --> <j2se version="1.7+" /> <jar href= "dist/applet_ComponentArch_DynamicTreeDemo/DynamicTreeDemo.jar" main="true" /> </resources> <applet-desc name="Dynamic Tree Demo Applet" main-class="appletComponentArch.DynamicTreeApplet" width="300" height="300"> </applet-desc> <update check="background"/> </jnlp>
base64
, uuencode
jnlp_embedded
parameter with it's value set to the Base64 encoded JNLP string. Make sure to include only the actual Base64 bytes without any encoding tool specific headers or footers.
<script src="https://www.java.com/js/deployJava.js"></script> <script> var attributes = {} ; <!-- Base64 encoded string truncated below for readability --> var parameters = {jnlp_href: 'dynamictree_applet.jnlp', jnlp_embedded: 'PCEtLSANCi8qDQogKiBDb ... bmxwPg==' } ; deployJava.runApplet(attributes, parameters, '1.6'); </script>
Some encoding tools may wrap the encoded string into several 76-column lines. To use this multi-line attribute value in JavaScript code, specify the attribute value as a set of concatenated strings. You can include the multi-line attribute value as is if the applet is deployed directly with the <applet>
HTML tag.
Open
in a browser to view the Dynamic Tree Demo applet that is launched by using the JNLP file embedded in the web page.AppletPage.html
Download source code for the Embedded JNLP example to experiment further.