Embedding JNLP File in Applet Tag
Trail: Deployment
Lesson: Deployment In-Depth
Section: Deployment Toolkit
Subsection: Deploying an Applet

Embedding JNLP File in Applet Tag

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:

The following steps describe how to embed a JNLP file in a web page to deploy an applet.

  1. Create a JNLP file for your applet. A sample file is shown next.
    <!-- href attribute contains relative path;
         codebase attribute not specified -->
    <jnlp href="dynamictree_applet.jnlp">
            <title>Dynamic Tree Demo</title>
            <vendor>Dynamic Team</vendor>
            <!-- Application Resources -->
            <j2se version="1.7+" />
            <jar href=
                 main="true" />
             name="Dynamic Tree Demo Applet"
         <update check="background"/>
  2. Encode the contents of the JNLP file using the Base64 scheme. You can use any Base64 encoding tool to encode the the JNLP file. Check the usage of the tool to create a string with Base64 encoding. Some examples of tools and web sites that may be used are as follows:
  3. When deploying the applet in a web page, specify the 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=""></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');

    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 AppletPage.html in a browser to view the Dynamic Tree Demo applet that is launched by using the JNLP file embedded in the web page.

Note:  If you don't see the applet running, you need to install at least the Java SE Development Kit (JDK) 7 release.

Note:  If you don't see the example running, you might need to enable the JavaScript interpreter in your browser so that the Deployment Toolkit script can function properly.

Download source code for the Embedded JNLP example to experiment further.

Previous page: Customizing the Loading Screen
Next page: Deploying a Java Web Start Application