Documentation

The Java™ Tutorials
Hide TOC
Ensuring the Presence of the JRE Software确保JRE软件的存在
Trail: Deployment
Lesson: Deployment In-Depth
Section: Deployment Best Practices部署最佳实践

Ensuring the Presence of the JRE Software确保JRE软件的存在

Rich Internet applications (RIAs) usually need a minimum version of the Java Runtime Environment (JRE) software to be present on the client machine. 富互联网应用程序(RIA)通常需要在客户机上提供Java运行时环境(JRE)软件的最低版本。When deploying a RIA, you need to ensure that client machines have the required version of the JRE software so that your RIA can function well. 在部署RIA时,您需要确保客户端机器具有所需版本的JRE软件,以便RIA能够正常运行。With the Deployment Toolkit script, you have at least two ways to handle this requirement.使用部署工具包脚本,您至少有两种方法来处理此需求。

Checking and Installing the Latest JRE Software When the User Accesses Your Web Site当用户访问您的网站时,检查并安装最新的JRE软件

The following example checks if a user has at least version 1.6.0_13 of the JRE software installed. 以下示例检查用户是否安装了至少1.6.0_13版的JRE软件。If not, the code installs the latest JRE software. 如果没有,代码将安装最新的JRE软件。See inline comments in the code.请参阅代码中的内联注释。

<script src="https://www.java.com/js/deployJava.js"></script>
<script> // check if current JRE version is greater than 1.6.0
    alert("versioncheck " + deployJava.versionCheck('1.6.0_10+'));
    if (deployJava.versionCheck('1.6.0_10+') == false) {                   
        userInput = confirm(
            "You need the latest Java(TM) Runtime Environment. " +
            "Would you like to update now?");        
        if (userInput == true) {  
    
            // Set deployJava.returnPage to make sure user comes back to 
            // your web site after installing the JRE
            deployJava.returnPage = location.href;
            
            // Install latest JRE or redirect user to another page to get JRE
            deployJava.installLatestJRE(); 
        }
    }
</script>

Installing the Correct JRE Software Only When the User Attempts to Use Your RIA只有当用户试图使用您的RIA时,才能安装正确的JRE软件

When you specify the minimum version of the JRE software in the runApplet or createWebStartLaunchButton function, the Deployment Toolkit script makes sure that the required version of the JRE software exists on the client before running your RIA.runAppletcreateWebStartLaunchButton函数中指定JRE软件的最低版本时,部署工具包脚本会确保在运行RIA之前,客户端上存在所需版本的JRE软件。

Use the runApplet function to deploy an applet, as shown in the following example. 使用runApplet函数部署小程序,如下例所示。The last parameter of the runApplet function is the minimum version that is required to run your applet (version 1.6).runApplet函数的最后一个参数是运行小程序所需的最低版本(1.6版)。

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

To deploy a Java Web Start application, use the createWebStartLaunchButton function with the correct minimum version parameter (version 1.6).要部署Java Web Start应用程序,请使用createWebStartLaunchButton函数和正确的最小版本参数(版本1.6)。

<script src="https://www.java.com/js/deployJava.js"></script>
<script> var url = "dynamictree_applet.jnlp";
    deployJava.createWebStartLaunchButton(url, '1.6.0');
</script>

The runApplet and createWebStartLaunchButton functions check the client's version of the JRE software. runAppletcreateWebStartLaunchButton函数检查客户端的JRE软件版本。If the minimum version is not installed, the functions install the latest version of the JRE software.如果未安装最低版本,功能将安装最新版本的JRE软件。


Previous page: Avoiding Unnecessary Update Checks
Next page: Questions and Exercises: Deployment In-Depth