Deploying RIAs in Mixed Environments

   
By Ed Ort, February 2010  

Articles Index

Rich Internet Applications (RIAs) — browser-based applications that present the kinds of engrossing user interfaces (UIs) and content previously found only in desktop applications — are becoming increasingly popular. In fact, for many developers, the browser is becoming the preferred deployment target for their applications. A lot of this increased popularity is due to the ubiquity of the Internet. But it's also due to improved uniformity in the way different browsers handle RIAs.

 
Not all RIAs run the same way in all user environments or can even be deployed in all user environments.

However, that improved uniformity does not mean that all RIAs run the same way in all user environments or that they can even be deployed in all user environments. Consider Java RIAs, that is, applets and Java Web Start applications. The latter are applications launched by Java Web Start technology. What if your applet requires the latest version of Java Plug-In software or a specific level of the Java Runtime Environment (JRE)? What if your Java Web Start application requires at least a minimum level of Java Web Start software installed? How do you detect whether the user's environment satisfies those requirements? If the user's environment does not meet your requirements, what actions can you take to ensure that your RIA successfully deploys and runs in those environments?

 
The Deployment Toolkit can help ensure that your Java RIAs can be deployed and launched consistently across different types of user environments.

Fortunately, there is an excellent tool available to help ensure that your Java RIAs can be deployed and launched consistently across different types of user environments. That tool is the Deployment Toolkit.

This article covers some mixed-environment deployment scenarios, that is, scenarios where you want your Java RIAs to successfully deploy and run in multiple types of environments. For example, you want your applet to deploy and take advantage of the latest Java Plug-In software if that version of the Java Plug-In software is installed. But you also want your applet to successfully deploy if the latest Java Plug-In software is not installed — although in that case, the applet won't be able to take advantage of the latest Java Plug-In features. In particular, this article shows you how you can use the Deployment Toolkit to successfully deploy and run RIAs in these mixed environments. Note that throughout the remainder of this article the term RIA refers to Java RIAs.

Contents
 
The Deployment Toolkit
Mixed-Environment Scenarios and Solutions
Summary
For More Information
Comments
 
The Deployment Toolkit
 
The Deployment Toolkit consists of a JavaScript library, an ActiveX control, and a plugin. The JavaScript library provides JavaScript functions that are designed to ease the deployment of RIAs. The ActiveX control and the plugin augment the capabilities of the JavaScript library.

The Deployment Toolkit, commonly referred to as DT, provides a web-based mechanism to detect and, if necessary, install or upgrade the JRE in a user's environment. The DT consists of a JavaScript library, an ActiveX control, and a plugin.

The ActiveX control and the plugin augment the capabilities of the JavaScript library, and are automatically installed when the JRE is installed. The ActiveX control is used when the client browser is Internet Explorer. The plugin is used when the client browser is Firefox or another Mozilla family browser. If the appropriate native component, that is, ActiveX control or plugin, is not installed, the functions in the JavaScript library are able to perform their tasks. However, if the appropriate native component is installed, those tasks can be performed in an enhanced way. For example, one of the functions in the JavaScript library, getJREs(), returns the latest version of the JRE installed in the user's environment or the Java family of the latest installed JRE. The Java family is the base level of the JRE, for example, if the user's environment has JRE 1.5.0_05 and 1.5.0_08 installed, the Java family is 1.5.0. However, with the appropriate native component installed, the function returns a list of all the installed JREs in the user's environment.

You can access the Deployment Toolkit script at http://www.java.com/js/deployJava.js, or for a deployment on secure web pages, you can access the script at
https://www.java.com/js/deployJava.js. The script exposes a single object, named deployJava, which contains the public functions listed in Table 1.

Table 1: Deployment Toolkit Library Functions
 
 
JavaScript Function
Description
createWebStartLaunchButton(jnlp, minimumVersion)
Generates a launch button for the specified jnlp URL. When clicked, the button ensures that an appropriate JRE is installed. It then launches the Java Web Start application. The minimumVersion parameter is the minimum JRE version necessary to run this application, for example, 1.5.0 or 1.6.0_18. If the minimumVersion parameter is not specified, its value defaults to 1.4.2. If an appropriate JRE is not detected, this function calls the installLatestJRE() function before launching the application. If minimumVersion is not supplied and no version of Java Web Start technology is found, this function calls the installJRE() function before launching the application.
getBrowser()
Returns the name of the client browser.
getJPIVersionUsingMimeType
Returns the version of the installed DT plugin.
getJREs()
If Internet Explorer is the client browser, returns the latest version of the JRE installed in the user's environment. For other browsers, returns the Java family of the latest installed JRE. However, if the ActiveX control or DT plugin appropriate for the browser is installed, the function returns a list of all the installed JREs in the user's environment.
getPlugin()
Returns the ActiveX control or DT plugin for the client browser.
installJRE(requestVersion)
Triggers the installation of the latest version of the JRE matching the specified requestVersion, or the latest JRE. If the DT plugin is not installed, this function calls the deployJava.installLatestJRE() function.
installLatestJRE()
Triggers the installation of the latest JRE. The exact effect of triggering an installation of the JRE depends on the user's platform and browser. It also depends on whether the DT plugin is installed. In some user environments, triggering an installation of the JRE means that the JRE is automatically downloaded. In other cases, the user's browser window is redirected to a JRE installation page from which the user can download the appropriate JRE.
isAutoUpdateEnabled
Returns true if the DT plugin is installed and the AutoUpdate feature is enabled. AutoUpdate is a DT plugin feature that the DT takes advantage of in installing or upgrading a JRE in the user's environment.
isPlugin2()
Returns true if plugin2, the "next-generation" Java Plug-In software introduced in JRE 6 Update 10, is installed. Note that plugin2 is not currently available for Mac OS environments.
isPluginInstalled()
Returns true if the ActiveX control or DT plugin is installed.
isWebStartInstalled(minimumVersion)
Returns true if an installation of Java Web Start technology of the specified minimumVersion is found. If minimumVersion is not specified, returns true for any installed version of Java Web Start technology.
launch(jnlp)
Launches a Java Web Start application using the Java Network Launching Protocol (JNLP) file at the jnlp URL.
launchWebStartApplication(jnlp)
Launches a Java Web Start application using the JNLP file at the jnlp URL.
runApplet(attributes, parameters, minimumVersion)
Ensures that an appropriate JRE is installed, generates an <applet> tag based on the supplied parameters, and then runs an applet. The minimumVersion parameter, which is optional, specifies the minimum version of the JRE needed to run the applet, for example, 1.5.0 or 1.6.0_18. If the minimumVersion parameter is not specified, its value defaults to 1.1, which means that the applet can run with any version of the JRE. If the minimum version of the JRE is not installed, this function calls installJRE(minimumVersion) to install it. The attributes parameter is an associative array that specifies the names and values of the attributes in the generated <applet> tag. The parameters parameter is an associative array that specifies the names and values of <param> tags in the generated <applet> tag.
setAdditionalPackages(packageList)
Sets the additional package list to be used by the kernel installer.
setAutoUpdateEnabled()
Sets the AutoUpdate feature on if the DT plugin is installed.
setEarlyAccess(enabled)
Sets preference to install Early Access versions if available.
setInstallerType()
Sets the preferred installer type to be automatically downloaded. The choices are: null (no installer type), online (normal online installer), or kernel (the core set of Java classes required by the JRE).
testForMSVM()
For an Internet Explorer client browser, determines the version installed.
testUsingActiveX(version)
For an Internet Explorer client browser, determines if the Active X control is installed.
testUsingMimeTypes(version)
For a client browser in the Mozilla family, determines the version installed.
versionCheck(version)
Returns true if there is a matching JRE version currently installed among those detected by the getJREs() function.
writeAppletTag(attributes, parameters)
Generates an <applet> tag with the specified attributes and parameters. Each key/value pair specified as attributes becomes an attribute of the generated <applet> tag. Each key/value pair specified as parameters becomes a <param> tag.
 

Suppose, for example, you want to run an applet that requires the user to have JRE 6 installed, or any JRE 6 update. You can invoke the runApplet(attributes, parameters, minimumVersion) function to do that as shown in the following script example:

   <script src="http://www.java.com/js/deployJava.js"></script>
   <script>
       var attributes = {code:'HelloWorld.class', archive:'HelloWorld.jar', width:300, height:200} ;
           var parameters = {name:thomas} ;
           var minimumVersion = '1.6.0' ;
       deployJava.runApplet(attributes, parameters, minimumVersion);
   </script>
 

In the previous example, the DT determines if JRE 6, or any JRE 6 update, is installed. If that version of the JRE is not installed, the DT calls deployJava.installJRE(1.6.0). If the DT plugin is installed, calling deployJava.installJRE(1.6.0) triggers the installation of JRE 1.6.0. If the DT plugin is not installed, this function calls deployJava.installLatestJRE() to install the latest JRE.

The DT then generates the following <applet> and <param> tags:

   <applet code="HelloWorld.class" archive="HelloWorld.jar" width=300 height=200>
   <param name="name" value="thomas">
   </applet>
 

The DT then executes the applet in JRE 6 or the JRE 6 update.

Here's another example. Suppose you want to deploy an application using Java Web Start technology and you require the user to have JRE 6 Update 10 or higher installed. You can invoke the deployJava.launch(jnlp) function to do that as shown in the following script example:

   <script src="http://www.java.com/js/deployJava.js"></script>
   <script>
       deployJava.launch('myapp.jnlp');
   </script>
 

The JNLP file, myapp.jnlp, for the application might look like this:

   <jnlp spec="6.0.10+" codebase="http://mycompany.com/jnlp" href="myapp.jnlp">
     <information>
       <title>My Java Web Start Application</title>
       <vendor>My Company</vendor>
       <description>This is a sample Java Web Start application.</description>
     </information>
     <update check="background"/>
     <resources>
       <j2se version="1.6.0_10" href="https://bitly.com/xyGWeN+"/>
       <jar href="myapp.jar"/>
     </resources>
    <application-desc main-class="myapp"/>
   </jnlp>
 

The DT launches the application based on the contents of the JNLP file, myapp.jnlp. The version value in the <j2se> element in the JNLP file indicates that the application runs on JRE 6 update 10 or higher.

Mixed-Environment Scenarios and Solutions

Let's take a look at some scenarios that involve multiple types of deployment targets, as well as approaches that you can take to successfully deploy an RIA across these mixed environments.

Scenario 1: Deploy an applet to JRE 6. Upgrade earlier versions of JRE to JRE 6.

In this scenario, you want your applet to successfully deploy and run in user environments that have JRE 6 or a JRE 6 update installed. However, you also want to upgrade user environments to JRE 6 if they only have an earlier version of the JRE installed. Your applet can then deploy in those upgraded environments. You can meet both of these objectives by running a script similar to the following:

   <script src="http://java.com/deployJava.js"></script>
   <script>
       var attributes = {code:'HelloWorld.class', archive:'HelloWorld.jar', width:300, height:200} ;
       var parameters = {name:thomas} ;
       var minimumVersion = '1.6.0' ;
       deployJava.runApplet(attributes, parameters, minimumVersion);
   </script>
 

This script is similar to the script shown earlier in The Deployment Toolkit section. As was the case in the previous example, the DT determines if JRE 6, or any JRE 6 update, is installed. If that version of the JRE is not installed, the DT either installs JRE 6 or the latest JRE 6 update. This depends on whether the DT plugin is installed. Furthermore, in some environments, the DT cannot automatically install the JRE. In these cases, it redirects the user's browser window to a JRE installation page from which the user can download JRE 6 or a JRE 6 update.

The DT then generates <applet> and <param> tags with parameters and values based on the attributes and parameters specified in the script. It then executes the applet in JRE 6 or the JRE 6 update — it does this whether that version of the JRE was already installed in the user's environment or whether it was installed as a result of running the script.

 
Starting with the release of JRE 6 Update 10, you can use JNLP to deploy applets as well as Java Web Start applications.

You can also meet the objectives of this scenario using JNLP. Starting with the release of JRE 6 Update 10, you can use JNLP to deploy applets as well as applications. Prior to that, and as early as JRE 1.4.0, you could use JNLP to deploy Java Web Start applications only. Here is a script that uses JNLP to deploy an applet if the user has JRE 6 or a JRE 6 update installed. If the user only has an earlier JRE version installed, the script upgrades the user's environment to JRE 6 or a JRE 6 update.

   <script src="http://www.java.com/js/deployJava.js"></script>
   <script>
       var attributes = {code:'myapplet.class', archive:'myapplet1.jar', width:300, height:200} ;
           var parameters = {fontSize:32, jnlp_href:'applet.jnlp'} ;
           var minimumVersion = '1.6.0' ;
           deployJava.runApplet(attributes, parameters, minimumVersion);
   </script>
 

The JNLP file might look like this:

   <jnlp spec="6.0" href="applet.jnlp">
     <information>
       <title>My Applet 1</title>
       <vendor>My Company</vendor>
       <description>This is a sample applet for deployment in mixed environments.</description>
     </information>
     <update check="background"/>
     <resources>
       <j2se version="1.6.0" href="https://bitly.com/xyGWeN+"/>
       <jar href="myapplet1.jar"/>
     </resources>
     <applet-desc name="My Applet 1" main-class="myapplet" width="300" height="200" />
    </jnlp>
 
Scenario 2: Deploy an applet using new plugin2 features of JRE 6 Update 18. Upgrade earlier versions of JRE to JRE 6 Update 18. Deploy a different applet where upgrade is not feasible.
 
JRE 6 Update 18 adds a number of new features and services to JNLP.

JRE 6 Update 18 adds a number of new features and services to JNLP. For example, it adds a new progress-class attribute that you can use to specify which class to use for displaying download progress.

In this scenario, you want to use JNLP to deploy an applet and take advantage of the new JNLP features introduced in JRE 6 Update 18. To do that, the user's environment needs to have JRE 6 Update 18, or later, installed, as well as plugin2, the next-generation Java Plug-In software. You also want to upgrade user environments to JRE 6 Update 18 or later if they only have an earlier version of the JRE installed. Your applet can then deploy in those upgraded environments. Some user environments might not be upgradable to JRE 6 Update 18. For those environments, you want to deploy an applet, although one that can't take advantage of the new JNLP features.

One approach to meeting those objectives is as follows:

  1. Create and compile two versions of the applet: one targeted to run on JRE 6, and the other targeted to run on a lower-level of the JRE such as JRE 5. When you compile the applet targeted to run on JRE 5, specify the compiler options -source 1.5 and -target 1.5. Package the applets in separate JAR files, for example, the JRE 5 applet in Hello5.jar and the JRE 6 applet in Hello6.jar.
     
  2. Create a JNLP file for use with JRE 6. Here is what the JNLP file might look like:
     
       <jnlp spec="6.0+" href="applet.jnlp">
         <information>
           <title>Hello Applet</title>
           <vendor>My Company</vendor>
           <description>This is a sample applet for deployment in mixed environments.</description>
         </information>
         <update check="background"/>
         <security></security>
         <resources>
           <j2se version="1.6+"/>
           <jar href="Hello6.jar"/>
         </resources>
         <applet-desc name="My Applet 2" main-class="Hello" width="300" height="200" />
        </jnlp>
    
     
  3. Create a script that upgrades the user's environment to JRE 6 Update 18 or later where possible. Here is what the script might look like:
     
       <script src="http://www.java.com/js/deployJava.js"></script>
       <script>
       var upgrade = false;
           if (deployJava.isPluginInstalled()) {
               upgrade = !(deployJava.versionCheck('1.6.0_18+'));
           } else {
               var agent = navigator.userAgent.toLowerCase();
               if (agent.indexOf('mac') != -1) {
                   upgrade = false;                                      // no way to upgrade on Mac OS
               } else if (deployJava.getBrowser() == 'MSIE') {
                   upgrade = true;
               } else if (deployJava.browserName == 'Mozilla Family') {
                   var jreList = deployJava.getJREs();
                   if ((jreList.length > 0) && (jrelist[0] < '1.6.0_18')) {
                       upgrade = true;
                   }
               }
           }
           if (upgrade) {
               deployJava.installLatestJRE();
           }
    
       </script>
    
     
    Notice that the script calls the deployJava.isPluginInstalled() function to determine if the ActiveX control or DT plugin is installed. If the ActiveX control or DT plugin is installed, the DT takes advantage of it when installing JRE 6 Update 18 or later through the deployJava.installLatestJRE() function. Java Web Start technology can also be used to install the updated JRE, however the installation process is not as user friendly.
     
    Also notice the test in the script for Mac OS. Currently, there is no way to upgrade the JRE on Mac OS using the DT.
     
  4. Create a script that deploys the JRE 6 version of the applet if the user's environment has JRE 6 installed, or deploys the JRE 5 version of the applet if JRE 6 is not installed. Here is what that script might look like:
     
       <script src="http://www.java.com/js/deployJava.js"></script>
       <script>
           var attributes = {code:'Hello.class', archive:'Hello5.jar', width:300, height:200} ;
               var parameters = {fontSize:32, jnlp_href:'applet.jnlp'} ;
               var minimumVersion = '1.5.0' ;
               deployJava.runApplet(attributes, parameters, minimumVersion);
       </script>
    
     
    This script deploys the appropriate applet using the JNLP file, applet.jnlp. The JNLP file specifies that the Hello6.jar applet requires a JRE in the JRE 6 family. That applet will be deployed to any user environment that has a JRE in the JRE 6 family installed, including environments that the DT upgraded to JRE 6 Update 18 or later. The applet will be able to take advantage of the new JNLP features in user environments that have JRE 6 Update 18 or later installed or where the DT upgraded the user's environment to JRE 6 Update 18 or later. The script specifies a minimum JRE version of JRE 5 to deploy the Hello5.jar applet. So the Hello5.jar applet will be deployed to any user environment that doesn't have a JRE in the JRE 6 family, but at a minimum, has JRE 5 installed.  
Scenario 3: Deploy an applet to a JRE in the JRE 5 family using new Java Plug-In software features of JRE 6 Update 10. Upgrade if JRE 6 installed, but less than Update 10.
 
The next-generation Java Plug-In software introduced in JRE 6 Update 10 provides various new features, such as built-in JNLP support and an improved user experience.

In this scenario, you want to deploy an applet to any JRE in the JRE 5 family. However, you also want to take advantage of the new features in the next-generation Java Plug-In software introduced in JRE 6 Update 10. Among the new features provided by the next-generation Java Plug-In software are built-in JNLP support and an improved user experience.

To meet these requirements, the user's environment needs to have JRE 6 Update 10 or higher installed, including the version of the Java Plug-In software for JRE 6 Update 10 or higher. That level of the Java Plug-In software allows you to deploy an applet to earlier versions of the JRE such as JRE 5. In addition, the user's environment needs JRE 5 or a JRE 5 update release installed. Applets that run with a version of the Java Plug-In software prior to JRE 6 Update 10 can only run in the corresponding version of the JRE. For example, the Java Plug-In software packaged in JDK 6 Update 7 allows you to run an applet only in JRE 6 Update 7. Because of this restriction, you want to upgrade user environments to the latest JRE 6 version if they have a JRE installed that is in the JRE 6 family, but that is at an update level lower than Update 10.

 
The next-generation Java Plug-In software allows you to deploy an applet to earlier versions of the JRE. Applets that run with an earlier version of the Java Plug-In software can only run in the corresponding version of the JRE.

The approach you can take to meet these requirements is similar to the approach in scenario 2. However, here you only need to create one version of the applet. After you create and compile the applet, you can take the following actions:

  1. Create a JNLP file that will be used to deploy the applet to a JRE in the JRE 5 family. Here is what the JNLP file might look like:
     
       <jnlp spec="6.0.10+" href="applet.jnlp">
         <information>
           <title>My Applet 3</title>
           <vendor>My Company</vendor>
           <description>This is a sample applet for deployment in mixed environments.</description>
         </information>
         <update check="background"/>
         <security></security>
         <resources>
           <java version="1.5*"/>
           <jar href="applet3.jar"/>
         </resources>
         <applet-desc name="My Applet 3" main-class="applet3" width="300" height="200" />
        </jnlp>
    
     
    Notice the 1.5* value for the version attribute in the <java> element. This specifies that the applet is supported on any JRE in the JRE 5 family.
     
  2. Create a script that upgrades the user's environment to the latest JRE 6 level if the user's environment has a JRE installed that is in the JRE 6 family, but that is at an update level lower than Update 10. The script does no upgrade if the user's environment has JRE 6 installed and is at Update 10 or higher, or if the JRE is in the JRE 5 family. Here is what the script might look like:
     
       <script src="http://www.java.com/js/deployJava.js"></script>
       <script>
       var new_plugin = false;
           if (deployJava.isPluginInstalled()) {
               new_plugin = deployJava.isPlugin2();
           }
           var browser = deployJava.getBrowser();
           if (deployJava.browserName2 == 'Chrome') {
               new_plugin = true;       // Chrome uses only plugin2, but may not support DT plugin
           }
    
           var upgrade = (deployJava.versionCheck('1.6.0')) && !new_plugin;
    
           var agent = navigator.userAgent.toLowerCase();
           if (agent.indexOf('mac') != -1) {
                upgrade = false;        // no way to upgrade on Mac OS
           }
           if (upgrade) {
               deployJava.installLatestJRE();
           }
    
    
       </script>
    
     
    Notice the test for the Chrome browser. Chrome supports the next-generation Java Plug-In software. However, it currently does not support the DT plugin, so the upgrade operation cannot take advantage of any enhanced features that the DT plugin offers.
     
  3. Create a script that deploys the applet to user environments that have a JRE installed that is in the JRE 5 family. Here is what that script might look like:
     
       <script src="http://www.java.com/js/deployJava.js"></script>
       <script>
           var attributes = {archive:'applet3.jar', width:300, height:200} ;
               var parameters = {fontSize:32, jnlp_href:'applet.jnlp'} ;
               var minimumVersion = '1.5.0' ;
               deployJava.runApplet(attributes, parameters, minimumVersion);
       </script>
    
     
    This script deploys the applet using the JNLP file, applet.jnlp. The JNLP file specifies that the applet in applet3.jar requires a JRE in the JRE 5 family. The deployJava.runApplet function in the script specifies a minimum JRE version of JRE 5 to deploy the applet.
     
  4. Run the upgrade script, then run the deployment script. Running the scripts in that order will upgrade the user's environment, as necessary, so that the deployment can take advantage of the next-generation Java Plug-In software.  
Scenario 4: Deploy Java Web Start application to static versioned JRE 5 Update 2. Use new JNLP features in JRE 6 Update 18.

In this scenario, you want to deploy a Java Web Start application using JNLP and you want to deploy it to static versioned JRE 5 Update 2, that is, you want to deploy it specifically to JRE 5 Update 2 and not to any newer or older versions or updates of the JRE. In addition, you want to take advantage of the enhanced JNLP features in JRE 6 Update 18. To meet these requirements, you can take the following approach:

  1. Create a JNLP file that will be used to deploy the applet to JRE 5 Update 2. Here is what the JNLP file might look like:
     
       <jnlp spec="6.0.10+" codebase="http://mycompany.com/..." href="application.jnlp";>
         <information>
           <title>My Application</title>
           <vendor>My Company</vendor>
           <description>This is a sample application for deployment in mixed environments.</description>
         </information>
         <update check="background"/>
         <security></security>
         <resources>
           <java version="1.5.0_02" href="https://bitly.com/xyGWeN+" /;/>
           <jar href="application.jar"/>
         </resources>
         <application-desc main-class="application"/>
        </jnlp>
    
     
  2. Create a script that determines whether the user's environment has both JRE 6 Update 18, or later, and JRE 5 Update 2 installed. The DT installs JRE 5 Update 2 if it is not installed. The DT installs the latest version of the JRE if JRE 6 Update 18 or later is not installed. Here is what the script might look like:
     
       <script src="http://www.java.com/js/deployJava.js"></script>
       <script>
       var need_latest = false;
    
           if (deployJava.isPluginInstalled()) {
               need_latest = !deployJava.versionCheck('1.6.0_18+');
               if (!deployJava.versionCheck('1.5.0_02') {
                    deployJava.installJRE('1.5.0_02');
               }
           } else {
               var agent = navigator.userAgent.toLowerCase();
               if (agent.indexOf('mac') != -1) {
                   need_latest = false;           // no way to upgrade on Mac OS
               } else if (deployJava.getBrowser() == 'MSIE') {
                   need_latest = true;
               } else if (deployJava.browserName == 'Mozilla Family') {
                   var jreList = deployJava.getJREs();
                   if ((jreList.length > 0) && (jrelist[0] < '1.6.0_18') {
                       need_latest = true;
                   }
               }
           }
           if (need_latest) {
               deployJava.installLatestJRE();
           }
           deployJava.launch('application.jnlp');
    
       </script>
    
     
    After installing the JREs as needed, the DT launches the application using the JNLP file application.jnlp.  
Scenario 5: Deploy Java Web Start application using new JNLP features if user's environment has JRE 6 Update 18. Otherwise, use earlier release of Java Web Start technology. Install JRE if user does not have Java Web Start technology installed.

In this scenario, you want to use Java Web Start technology to deploy an application and take advantage of the new JNLP features introduced in JRE 6 Update 18. To do that, the user's environment needs to have JRE 6 Update 18, or later, installed. In addition, you want to use an earlier version of Java Web Start technology to deploy the application for user environments that have an earlier version of the JRE installed. Also, you want to install the latest version of the JRE for user's environments that do not already have Java Web Start technology installed.

Here is an approach that you can take to meet those requirements:

  1. Create a JNLP file for use with JRE 6 Update 18. Here is what the JNLP file might look like:
     
       <jnlp href="draw.jnlp">
         <information>
           <title>My Java Web Start Application</title>
           <vendor>My Company</vendor>
           <description>This is a sample application to be launched by the Java Web Start technology version in JRE 6 Update 18 or later.</description>
         </information>
         <update check="background"/>
         <resources>
           <java version="1.6+" href="https://bitly.com/xyGWeN+" />
           <jar href="application.jar"/>
         </resources>
         <application-desc main-class="application"/>
       </jnlp>
    
     
     
    JRE 6 Update 18 removes the requirement that a JNLP file needs to specify a codebase attribute for a Java Web Start application.
    Notice that this JNLP file specifies no codebase. JRE 6 Update 18 removes the requirement that a JNLP file must specify a codebase attribute for a Java Web Start application.
     
  2. Create a JNLP file for use with JRE 6 Update 17 or earlier. Here is what the JNLP file might look like:
     
       <jnlp codebase="http://yourcompany.com" href="draw.jnlp">
         <information>
           <title>My Java Web Start Application</title>
           <vendor>My Company</vendor>
           <description>This is a sample application to be launched by the Java Web Start technology version in JRE 6 Update 17 or earlier.</description>
         </information>
         <update check="background"/>
         <resources>
           <java version="1.6+" href="https://bitly.com/xyGWeN+" />
           <jar href="application.jar"/>
         </resources>
         <application-desc main-class="application"/>
       </jnlp>
    
     
    Notice that this JNLP file specifies a codebase because it's required in JNLP files in JRE 6 Update 17 or earlier.
     
  3. Create a script that launches the application using the appropriate JNLP file. Here is what the script might look like:
     
       <script src="http://www.java.com/js/deployJava.js"></script>
       <script>
           if (deployJava.versionCheck('1.6.0_18+')) {
               // 6u18+ available, use no codebase JNLP file
               deployJava.createWebStartLaunchButtonEx("draw.jnlp", "1.6.0_18");
           } else {
               if (deployJava.isWebStartInstalled()) {
                  // use existing webstart on client
                  deployJava.createWebStartLaunchButton("http://yourcompany.com/draw_with_codebase.jnlp");
               } else {
                  // no Java Web Start technology, install latest JRE
                  if (deployJava.installLatestJRE()) {
                     // assume installLatestJRE installs 6u18+
                     deployJava.createWebStartLaunchButtonEx("draw.jnlp", "1.6.0_18");
             }
               }
           }
    
       </script>
    
    
     
    If JRE 6 Update 18 or later is installed in the user's environment, the script calls deployJava.createWebStartLaunchButtonEx("draw.jnlp", "1.6.0_18"). This generates a launch button that launches the application using the no codebase version of the draw.jnlp file, that is, the JNLP file for use with the Java Web Start version in JRE 6 Update 18 or later.
     
    If JRE 6 Update 18 or later is not installed, the script calls deployJava.isWebStartInstalled() to determine whether Java Web Start technology is installed. If Java Web Start technology is installed, the script calls deployJava.createWebStartLaunchButtonEx("http://yourcompany.com/draw_with_codebase.jnlp"). This generates a launch button that launches the application using the codebase version of the draw.jnlp file, that is, the JNLP file for use with the Java Web Start technology version in JRE 6 Update 17 or earlier.
     
    If JRE 6 Update 18 or later is not installed and neither is Java WebStart, the script calls deployJava.installLatestJRE() to install the latest version of the JRE, where possible. It then calls deployJava.createWebStartLaunchButtonEx("draw.jnlp", "1.6.0_18"), which generates a launch button that launches the application using the no codebase version of the draw.jnlp file, that is, the JNLP file for use with the Java Web Start technology version in JRE 6 Update 18 or later.
     
Scenario 6: Deploy an applet in Windows and Mac OS. In Windows environments that have plugin2 installed, deploy the applet using JNLP. Otherwise, generate an <applet> tag to deploy the applet. The applet requires JRE 5 or later.

In this scenario, you want to deploy an applet in user environments that run either the Windows or Mac OS. You want to use JNLP to deploy the applet in Windows environments that have plugin2 installed. In Windows environments that do not have plugin2 installed, you want to deploy the applet using the <applet> tag. You also want to use the <applet> tag to deploy the applet in Mac environments. Finally, you require the user's environment to have JRE 5 or later installed to launch the applet.

Here is a way to meet those requirements:

  1. Create a JNLP file for use with plugin2. Here is what the JNLP file might look like:
     
       <jnlp href="HelloWorldApplet.jnlp">
         <information>
           <title>Hello World Applet</title>
           <vendor>My Company</vendor>
           <description>This is a sample applet to be launched by Java Web Start technology.</description>
           <offline-allowed/>  //the applet can run offline
         </information>
    
         <resources>
           <java version="1.5+" href="https://bitly.com/xyGWeN+" />
           <jar href="HelloWorld.jar"/>
         </resources>
         <applet-desc main-class="HelloWorld" name="HelloWorld" width="300" height="200"/>
       </jnlp>
    
     
     
    Since its introduction in JRE 6 Update 10, plugin2, eliminated the need for a JNLP file to specify a codebase attribute for an applet.
    Notice that this JNLP file specifies no codebase. Recall that JRE 6 Update 18 removes the requirement that a JNLP file must specify a codebase attribute for a Java Web Start application. However, since its introduction in JRE 6 Update 10, plugin2 eliminated the need for a JNLP file to specify a codebase attribute for an applet.
     
  2. Create a script that uses Java Web Start technology to deploy the applet if plugin2 is installed, or that creates an <applet> tag to deploy the applet if plugin2 is not installed. Note that plugin2 is not currently available for Mac environments, so in those environments, the applet is deployed using an <applet> tag. Here is what that script might look like:
     
       <script src="http://www.java.com/js/deployJava.js"></script>
       <script>
    
           if (deployJava.isPlugin2()) {
                      // Launch as JNLP style applet if plugin2 is available
                  var attributes = {jnlp_href:'HelloWorldApplet.jnlp'} ;
                  } else {
                      // old plugin and MacOS case  (currently isPlugin2() always false for MacOS)
                     var attributes = {code:'HelloWorld.class', archive:'HelloWorld.jar', width:300, height:200} ;
                  }
    
           // minimum Java needed:  1.5 or above
               var minimumVersion = '1.5.0' ;
    
               deployJava.runApplet(attributes, parameters, minimumVersion);
       </script>
    
     
    Notice the minimumVersion value of 1.5.0. To run, the applet requires JRE 5 or later.  
Summary

In this article, you've seen how the Deployment Toolkit can help ensure that your Java RIAs can be deployed and launched consistently across different types of user environments. In addition, you've seen how DT's extensive set of JavaScript functions can help you perform a wide variety of deployment-related tasks — anywhere from determining if DT native components are installed in a user's environment, to triggering the installation of the latest JRE, to generating appropriate tags and then running an applet, to generating a button to launch a Java Web Start application.

For More Information
Rate This Article
 
 
Comments
Terms of Use