jdt

Java deployment toolkit (JDT) – How to use it

The Java Deployment Toolkit allows developers to easily deploy their applets and applications to a large variety of clients. The Deployment Toolkit script is a set of JavaScript functions that, help developers deploy their rich Internet applications (RIAs) consistently across various browsers and operating system configurations.
The script evaluates the underlying browser and operating system, and automatically generates the HTML code that is required, in order for a Rich Internet Application to be deployed. Moreover, this script can also ensure that the required version of the Java Runtime Environment (JRE) software is present on the client machine. Finally, the Deployment Toolkit script was introduced in the Java Platform, Standard Edition 6 update 10 release.

Location of Deployment Toolkit Script

The Deployment Toolkit script is located at the following web addresses:

Important: Use the 2nd link in order to deploy and launch your application, because the 1st link is currently being phased out. In this way, you will avoid any content warnings when your web page is loading.

Note: The JavaScript code in these locations has been minimized so that it can load quickly. You can view the human readable version of the JavaScript code with associated comment blocks at https://www.java.com/js/deployJava.txt.

The JavaScript interpreter should be enabled in the client’s browser so that the Deployment Toolkit script can run and deploy your RIA properly.

Deploying an Applet

You can deploy applets by using the runApplet function of the Deployment Toolkit script. The runApplet function ensures that the required minimum version of the Java Runtime Environment (JRE) software exists on the client and then, runs the applet. The runApplet function generates an HTML <applet> tag with the information provided.

You can deploy applets by specifying the deployment options as attributes and parameters of the <applet> tag. You can also specify deployment options in a Java Network Launch Protocol (JNLP) file to take advantage of advanced features.

Function signature: runApplet: function(attributes, parameters, minimumVersion)

Parameters:

  • attributes – The names and values of the attributes of the generated <applet> tag
  • parameters – The names and values of the <param> tags in the generated <applet> tag
  • minimumVersion – The minimum version of the JRE software that is required to run this applet

You can deploy an applet by using one of the following methods:

  • Specify the deployment options as attribute and parameter name-value pairs:
    The name-value pairs are translated into attributes and nested <param> tags in the generated <applet> tag. An example is shown below:

    <script src="https://www.java.com/js/deployJava.js"></script>
    <script>
        var attributes = {codebase:'',
                          code:'.class',
                          archive:'.jar',
                          width:500, height:500};
        var parameters = {permissions:'sandbox'};
        var version = '1.6';
        deployJava.runApplet(attributes, parameters, version);
    </script>
    

    The above sample code snippet shows how to launch an applet with one parameter, called permissions. The permissions parameter determines if the applet is executed inside the security sandbox, or if it requires permissions to access resources outside the sandbox.

  • Use the jnlp_href parameter to specify deployment options in a JNLP file:
    Again, the name-value pairs are translated into attributes and nested <param> tags in the generated <applet> tag. An example is shown below:

    <script src="https://www.java.com/js/deployJava.js"></script>
    <script>
        var attributes = {code:'', width:500, height:500}; 
        var parameters = {jnlp_href: 'javaExample.jnlp'}; 
        deployJava.runApplet(attributes, parameters, '1.6'); 
    </script>
    

    The “javaExample.jnlp” file has the following form:

    javaExample.jnlp:

    <?xml version="1.0" encoding="UTF-8"?>
     <jnlp href="javaExample.jnlp">
         <information>
           <title>Java Example</title>
           <vendor>A sample name</vendor>
           <offline-allowed/>
         </information>
         <resources>
           <j2se version="1.6+"
                 href="http://java.sun.com/products/autodl/j2se" />
           <jar href=".jar" main="true" />
         </resources>
         <applet-desc 
             name="Java Example"
             main-class="Main_Class"
             width="500"
             height="500">
         </applet-desc>
     </jnlp>
    
  • Specifying attribute and parameter name-value pairs as well as a JNLP file.
    An example that specifies the applet tag attributes and JNLP parameters is shown below:

    var attributes = {codebase:'’, code:'.class', archive:'.jar', width:500, height:500}; 
    var parameters = { jnlp_href:'javaExample.jnlp'}; 
    var version = '1.6'; 
    deployJava.runApplet(attributes, parameters, version);
    

Important: The applet tag and the JNLP file provide overlapping mechanisms to specify the same information. A developer must be aware of the specifications and how the attributes get their final value, when some deployment options have different values in the attribute name-value pairs and in the JNLP file.

Deploying a Java Web Start Application

You can deploy Java Web Start applications by using the createWebStartLaunchButton function of the Deployment Toolkit script. Java Web Start applications are launched using Java Network Launch Protocol (JNLP). The createWebStartLaunchButton function generates an HTML anchor tag, that link to the Java Web Start application’s JNLP file.

When the end user clicks the Launch button, the Deployment Toolkit script ensures that the appropriate Java Runtime Environment (JRE) software is installed and then launches the Java Web Start application.

Function signature: createWebStartLaunchButton: function(jnlp, minimumVersion) or createWebStartLaunchButton: function(jnlp)

Parameters:

  • jnlp – The URL of the JNLP file containing the deployment information for the Java Web Start application. This URL should be an absolute path.
  • minimumVersion – The minimum required version of the JRE software, in order for this application to be executed.

Also, a Java Web Start Application can be deployed simply by creating a JNLP file that describes only the title, vendor, java version, jar file(s), and main class of the application. Then, the application can be deployed, by simply providing a link to the JNLP file on your web page.

Many other elements can be added to the JNLP file to control the user experience, security, and update process of your application, or to take advantage of several other features of the Java Network Launching Protocol (JNLP).

If the application wants to use some advanced features of JNLP and Java Web Start, that were introduced in a particular version, you may want to ensure that at least that version is installed, before launching the Java Web Start.

Java Network Launch Protocol

The Java Network Launch Protocol (JNLP) enables an application to be launched on a client desktop, by using resources that are hosted on a remote web server. The Java Plug-in software and Java Web Start software are considered JNLP clients, because they can launch remotely hosted applets and applications on a client desktop.

Both applets and Java Web Start applications can be launched by using the JNLP protocol. RIAs that are launched by using the JNLP protocol have access to:

  • Access to JNLP extensions.
  • Access to the JNLP APIs.
  • Version selection and more.

You can improve the user experience of your rich Internet application (RIA) using some of the following practices:

  • Sign the RIA using a certificate from a recognized certificate authority. Make sure that all artifacts are signed, and that the certificate has not expired.
  • Request the minimum level of permissions that is needed. If the RIA does not require unrestricted access to a user’s system, specify the permission level to be sandbox.
  • Optimize the size of “.jar” files and related resources, so that your RIA can load more quickly.
  • Enable the version download protocol and use background update checks to enable your RIA to start quickly.
  • Make sure that the client has the required version of the Java Runtime Environment software.

Checking the Client JRE Software Version

There are many reasons to check if a particular version of the Java Runtime Environment (JRE) software is available on a client machine. For example, your application may require features that were introduced in the latest JRE. In case that this requirement is not satisfied, you can redirect the user to a different page, in order to download the latest JRE.

You can use the Deployment Toolkit script’s versionCheck function to check if a particular version or range of JRE versions is installed on the client.

Function signature: versionCheck: function(versionPattern)

Parameters:

  • versionPattern – String specifying the version or range of versions, such as such as “1.6”, “1.6.0*” (1.6.x family), and “1.7.0_02+” (any version greater than or equal to 1.7.0_02).

A sample example, where we request that at least JRE 1.6 must be installed, is shown below:

<script src="https://www.java.com/js/deployJava.js"></script>
<script>
    if (deployJava.versionCheck('1.6+')) {            
        var url = "<url_to_JNLP_file>";
        deployJava.createWebStartLaunchButton(url, '1.6.0'); 
    }
    else {
        document.location.href="http://oracle.com";
    }
</script>

Sotirios-Efstathios Maneas

Sotirios-Efstathios (Stathis) Maneas is a PhD student at the Department of Computer Science at the University of Toronto. His main interests include distributed systems, storage systems, file systems, and operating systems.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
Back to top button