Java Web Start 开发向导

来源:互联网 发布:linux exec函数 编辑:程序博客网 时间:2024/04/28 10:42

前言: 在java开发的早期,重点被放在了客户端开发。语言中对于applet和安全下载的支持对于万维网(WWW)的发布看上去是个不错的主意。但是现实是java最大的成功在于服务器端,java的强大功能和适应性赢得了服务器端开发者的心。同时,客户端的开发落后了。棘手的开发问题限制了applet的效用,开发者被迫转向基于浏览器的瘦客户端。Java Web Start 软件使您可以从 Web 下载和运行 Java 应用程序。而且提供一种单击一次即可激活应用程序的便捷方法;保证您始终运行最新版本的应用程序;避免了复杂的安装或升级过程。

官方提供的开发文档:http://docs.oracle.com/javase/8/docs/technotes/guides/javaws/

JNLP API (JavaDoc):http://docs.oracle.com/javase/8/docs/jre/api/javaws/jnlp/

简单使用(非开发)参考:

一、简介

  Java Web Start is an application-deployment technology that gives you the power to launch full-featured applications with a single click from your Web browser. You can now download and launch applications, such as a complete spreadsheet program or an Internet chat client, without going through complicated installation procedures.

  Java Web Start是一个应用程序的部署技术,能从您的网页浏览器中单击启动功能完备应用程序。您现在可以下载和启动应用程序,如一个完整的电子表格程序或一个互联网聊天客户端,而不需要通过复杂的安装程序。

  With Java Web Start, you launch applications simply by clicking on a Web page link. If the application is not present on your computer, Java Web Start automatically downloads all necessary files. It then caches the files on your computer so the application is always ready to be relaunched anytime you want—either from an icon on your desktop or from the browser link. And no matter which method you use to launch the application, the most current version of the application is always presented to you.

  使用java web start,你启动应用程序只需点击一个网页链接。如果应用程序在您的计算机上不存在,java web start自动下载所有必需的文件。当缓存的文件在你的计算机上,你可以在任何时间通过一个桌面图标或者网页的链接来运行这个程序。并且无论你是通过哪种方式来启动应用程序,该应用程序都是最新版本的。

二、开发向导

2.1 Overview(简介)

Java Web Start Technology

  Java Web Start is a helper application that gets associated with a Web browser. When a user clicks on a link that points to a special launch file (JNLP file), it causes the browser to launch Java Web Start, which then automatically downloads, caches, and prompts the user to run the given Java Technology-based application. Prompting for future launches of the application can be turned off by the user.

  Java Web Start是一个通过浏览器获取的辅助应用程序。当用户点击一个链接,而这个链接指向一个特殊的启动文件(JNLP文件),它将会是浏览器启动Java Web Start,然后自动下载,缓存,并提示用户运行Java应用程序。这个程序的运行用户可以随时进行关闭。

  From a technology standpoint, Java Web Start has a number of key benefits that make it an attractive platform to use for deploying applications:

  从技术的角度看,java web start有一些关键的好处,使得它成为一个有吸引力的部署应用程序的平台:


  • Java Web Start is built exclusively to launch applications written to the Java(TM) Platform Standard Edition. Thus, a single application can be made available on a Web server and then deployed on a wide variety of platforms, including Windows 98/NT/2000/ME/XP, Linux, and the Solaris Operating Environment. The Java platform has proven to be a very robust, productive, and expressive development platform, leading to a significant cost savings due to minimized development and testing costs.
  • Java Web Start是一个专门的运行标准版Java应用程序的平台。因此,一个单独的应用程序可以在服务器上被提供,然后可以部署在多种平台上,包括Windows 98 / NT / 2000 /ME/ XP,Linux和Solaris等操作环境。Java平台已经被证明是一个非常强大的且富有成效的强大表现力的开发平台,我们通过较少的开发与测试从而显著节约了开发成本。
  • Java Web Start supports multiple revisions of the Java Platform Standard Edition. Thus, an application can request a particular version of the platform it requires, such as Java SE 1.5.0. Several applications can run at the same time on different platform revisions without causing conflicts, and Java Web Start can automatically download and install a revision of the platform if an application requests a version that is not installed on the client system.
  • Java Web Start 支持多个版本的Java标准版平台。原因在于,一个应用程序可以请求一个它所需要的一个特定版本的平台。例如Java SE1.5.0 版本的应用程序可以同时运行在不同平台上而不发生冲突,如果应用程序所需要的运行版本没有安装,那么Java Web Start会自动下载并安装相应的版本的运行环境。
  • Java Web Start allows applications to be launched independently of a Web browser. This can be used for off-line operation of an application, where launching through the browser is often inconvenient or impossible. The application can also be launched through desktop shortcuts, making launching the Web-deployed application similar to launching a native application.
  • Java Web Start允许应用程序独立于Web浏览器运行。因此我们可以离线操作一个应用程序,因为有时候通过浏览器运行是不方便或者不可能的。应用程序也可以通过桌面快捷方式启动,使得我们可以像启动本地应用程序一样运行Web部署的应用程序。
  • Java Web Start takes advantage of the inherent security of the Java Platform.Sandbox applications are run in a protective environment with restricted access to local disk and network resources. Users must also agree to run the application the first time it is launched.
  • Java Web Startt利用Java平台的固有安全性。在具有受限访问本地磁盘和网络资源的保护环境中运行的应用程序的应用程序。用户必须在第一次运行应用程序的时候允许其运行。
  • Applications launched with Java Web Start are cached locally. Thus, an already-downloaded application is launched on par with a traditionally installed application.
  • 应用程序通过Java Web Start进行缓存到本地然后在运行。因此已经下载的应用程序可以像传统安装的应用程序一样运行。
  The technology underlying Java Web Start is the Java Network Launching Protocol & API (JNLP). This technology was developed via the Java Community Process (JCP). Java Web Start is thereference implementation (RI) for the JNLP specification. The JNLP technology defines, among other things, a standard file format that describes how to launch an application called a JNLP file.

  Java Web Start的技术基础是Java Network Launching Protocol&API(JNLP)。这项技术是由Java程序开发社区(JCP)开发的。Java Web Start的参考并实现了JNLP规范。除此之外,JNLP技术也定义了JNLP文件的标准格式,也就是定义了如何调用JNLP文件启动一个应用程序的规范。

Security

  Java Web Start is built on top of the Java SE platform, which provides a comprehensive security architecture. Applications launched with Java Web Start, by default,run without permissions in a restricted environment ("sandbox") with limited access to files and network. Users are also shown a security warning and prompted for permission to run these applications. Thus, launching applications using Java Web Start maintains system security and integrity.

  Java Web Start是建立在顶层的Java SE平台上的,这个平台提供了全面的安全体系结构。默认情况下,通过Java Web Start来运行应用程序,程序会在没有任何权限的情况下运行在受限制的环境中("sandbox"),并限制访问文件与网络。而且用户也会得到一个安全警告,并提示运行这些应用程序的权限。因此,通过使用Java Web Start来运行应用程序可以维护系统的安全性和完整性。
  An application can request unrestricted access to your system. Java Web Start will display a Security Warning dialog when the application is launched for the first time. The security warning shows information about the publisher of the application, the location from which the application is accessed, and the level of access requested. If you agree to the risk, then the application will be launched. The information about the origin of the application is based on digital code signing.
  一个应用程序可以请求不受限制的访问您的系统。Java Web Start会在第一次运行应用层程序的时候显示安全警告对话框。该安全警告显示了应用程序的发布服务器的信息,访问应用程序的位置和请求的访问级别。如果你同意风险,那么应用程序将被启动。有关应用程序的起源的信息是基于数字代码签名。

Where to find Java Web Start

Java Web Start is included in the Java Runtime Environment available at http://java.sun.com. The JNLP specification can be found atJSR 56: Java Network Launching Protocol and API.

Using Java Web Start Software

Java Web Start allows you to launch Java-technology-based applications directly from the Web. An application can be launched in three different ways:

Java Web Start允许我们通过Web运行Java应用程序。而这个Java应用程序可以通过三种方式来运行:

  1. From a Web browser by clicking on a link.(通过点击浏览器上的链接)
  2. From desktop icons or the Start Menu.(通过桌面图标或者开始菜单)
  3. From the Java Cache Viewer(通过Java Application Cache Viewer)

Regardless of which way is used, Java Web Start will connect back to the Web server each time an application is launched to check whether an updated version of the application is available.

无论哪种方式,Java Web Start在每次启动缓存下来的应用程序时都会连接服务器检查是否有更新版本。

Launching from a Web browser


  Point your web browser to a page with a link to a jnlp application, and click on that link.
  通过点击浏览器包含指向jnlp应用程序的超链接。
  A security dialog will pop up with information about the origin of the application based on who digitally signed the code, and the level of access requested. The application will run only if you decide to trust the vendor.
  一个安全对话框将弹出关于基于数字签名的应用程序的源代码的起源的信息,以及请求的访问级别。只有当您决定信任供应商时,应用程序才会运行。
  That is really all there is to using Java Web Start, but how does it work? The HTML links that launch the applications are, in fact, standard HTML links. However, instead of pointing to another Web page, they link to a special configuration file called a JNLP file. The Web browser examines the file extension and/or the MIME type of the file, and sees that it belongs to Java Web Start. It then launches Java Web Start with the downloaded JNLP file as an argument. Java Web Start proceeds with downloading, caching, and running the application as directed by the JNLP file.

  上面介绍的是如何使用Java Web Start,但是它是如何工作的?事实上,HTML上启动应用程序的超链接就是标准的HTML链接。然而,这个超链接不像往常一样指向另一个网页,而是链接到了一个特殊的JNLP配置文件。Web浏览器将会检查文件的扩展名或者文件的MIME类型,从而确定该文件属于Java Web Start。然后启动Java Web Start并且下载JNLP文件作为参数来下载,缓存和运行应用程序。

Launching from desktop icons and the Start Menu (Microsoft Windows and Solaris, Linux, and Mac OS X running GNOME 2.0+)

  Java Web Start technology can automatically create shortcuts for your application on the desktop and in the Start Menu for Web-deployed applications developed with Java technology. You can use the Java Control Panel to control the shortcut settings. Shortcuts can also be added by using the Java Web Start Cache Viewer, using the install shortcut menu item.

  Java Web Start技术可以为服务器上部署的Java应用程序自动的在桌面和开始菜单创建快捷方式。你可以通过Java控制面板来控制快捷键的设置。快捷键也可以使用Java Web Start Cache Viewer通过安装快捷菜单项来添加。

Using Java Web Start Software Behind a Proxy Server/Firewall

  Java Web Start software must be configured with the correct proxy settings in order to launch applications from outside your firewall. Java Web Start software will automatically try to detect the proxy settings from the default browser on your system (Internet Explorer or Netscape browsers on Microsoft Windows, and Netscape browsers on the Solaris Operating Environment and Linux). Java Web Start technology supports most web proxy auto-configuration scripts. It can detect proxy settings in almost all environments.
  Java Web Start软件为了运行防火墙外的应用程序,我们必须正确配置代理设置。Java Web Start软件会自动尝试从您的系统上的默认浏览器检测代理设置(在Windows系统会检测Internet Explorer,在Solaris操作系统或者Linux操作系统会检测Netscape浏览器)。Java Web Start技术支持大多数Web自动配置脚本,并且可以在任何环境中检测代理设置。
  You can also use the Java Web Start Control Panel to view or edit the proxy configuration. Refer to theJava Control Panel for more details.

  你也可以通过Java Web Start控制面板来查看和编辑代理设置。查看Java Control Panel来获取更多细节。

Requirements

Desktop/Client requirements:

  The client machine requires support for the Java Runtime Environment (JRE), version 1.3 or later. Java Web Start is available for Windows 98/NT/2000/ME/XP, the Solaris Operating Environment, and Linux.

  客户端至少需要有1.3或者之后版本的JRE环境。Java Web Start可以在Windows 98/NT/2000/ME/XP、Solaris和Linux环境下运行。

Server requirements:
  Applications can be deployed from any standard Web server. In order to use Java Web Start, the Web server must be configured with support for a new MIME type. SeeSetting Up the Web Site.

  应用程序可以部署在任何标准的Web服务器上。为了使用java web start,Web服务器必须配置一个新的MIME类型的支持。查看Setting Up the Web Site。

2.2 Setting Up the Web Site(服务器设置)

Introduction

  Java Web Start leverages existing Internet technology, such as the HTTP protocol and Web servers, so existing infrastructure for deploying HTML-based contents can be reused to deploy Java Technology-based applications using Java Web Start.
  Java Web Start利用了现有的网络技术,例如HTTP协议和Web服务器,因此利用现有的基础设施我们完全可以使用Java Web Start来部署Java应用程序。
  In order to deploy your application to client machines, you must make sure that all files containing your application are accessible through a Web server. This typically amounts to copying one or more JAR files, along with a JNLP file, into the Web server's directories. The set-up required for enabling the Web site to support Java Web Start is very similar to deploying HTML-based contents.The only caveat is that a new MIME type needs to be configured for the Web server.

  为了将你的应用程序部署到客户端的机器上,你必须确保包含应用程序的所有文件都可以通过Web服务器访问。因为这通常是从Web服务器的目录中复制一个或多个JAR文件,以及一个JNLP文件。为了使网站像部署基于HTML内容一样,启动Java Web Start 。唯一需要注意的是我们需要为Web服务器配置一个新的MIME类型。

Basic Steps(基本步骤)

1. Configure the Web server to use the Java Web Start MIME type

  Configure the Web server so that all files with the .jnlp file extension are set to the application/x-java-jnlp-file MIME type.

  配置Web服务器,这样所有已.jnlp为扩展名的文件都设置为 application/x-java-jnlp-fileMIME类型。

  Most Web browsers use the MIME type returned with the contents from the Web server to determine how to handle the particular content. The server must return application/x-java-jnlp-file MIME type for JNLP files in order for Java Web Start to be invoked.

  大多数Web浏览器利用从Web服务器上返回的MIME类型来确定如何特定内容。服务器必须为JNLP文件返回application/x-java-jnlp-file MIME类型,从而Java Web Start才会被调用。

  Each Web server has a specific way in which to add MIME types. For example, for the Apache Web server you must add the following line to the .mime.typesconfiguration file:

  每个Web服务器都有一个特定的方式来添加MIME类型。例如,对于Apache Web服务器必须添加以下行到mime.types配置文件:

application/x-java-jnlp-file JNLP
Check the documentation for the specifics of your Web server.(因此你需要检查您的Web服务器的具体文档。)
2. Create a JNLP file for the application

  The easiest way to create this file is to modify an existing JNLP file to your requirements.
  创建这个文件的最简单的方法是根据你自己的要求修改现有的JNLP文件。
  The syntax and format for the JNLP file is described in a later section.

  对JNLP文件的语法和格式是在后面的章节中描述。

3. Make the application accessible on the Web server

Ensure your application's JAR files and the JNLP file are accessible at the URLs listed in the JNLP file.

确保你的应用程序的jar文件和JNLP文件,在你JNLP文件所列举的URL是可访问的。

4. Create the web page that launches the application

See the next chapter, Creating the Web Page that launches the Application, for details on step 4.

2.3 Creating the Web Page That Launches the Application(创建启动应用程序的网页)

Introduction

The following information predates the introduction of the Deployment Toolkit script in the Java SE 6 update 10 release.

See Deployment in the Browser for information about using the Deployment Toolkit script.

  In order for an application to be launched from a web page via JNLP, the page must include a link to the JNLP file. E.g., to be able to launch application app.jnlpon a web sitehttp://www.MySite.com, the page needs to include the following link:

  为了让一个应用程序可以从网页上通过JNLP来运行,这个页面必须包含一个链接到JNLP文件的一个链接。例如,在http://www.MySite.com网站上链接到启动应用程序的app.jnlp文件,这个网页需要包含下面的链接:

<a href=http://www.MySite.com/app.jnlp>Launch the application</a>
  It may be the case, however, that Java Web Start is not installed on the user's computer. Thus the page needs to include logic (scripts) to take account of this. In fact, the page should include logic for the following:
  当然也可能遇到用户的计算机未安装Java Web Start的情况。因此,该页面需要包括逻辑(脚本)来考虑这个。事实上,页面应该包括以下的逻辑:

Detect if Java Web Start is installed(检测是否安装java web start)

  • If so, launch the application.
  • If not, detect if user is running IE on Window.
    • If so, provide link to a page that can auto-install the JRE for Windows
    • If not, provide a link to the general download page for the JDK/JRE.
The scripts, and the HTML for the auto-install page, are discussed below.

我们将会在下面讨论关于如何在HTML中嵌入脚本并自动安装。

Detecting if Java Web Start is installed on Netscape

Here is the first script that should be run on a web page for launching an application via JNLP:
这是要运行在一个网页上通过JNLP启动应用程序第一个脚本:

<SCRIPT LANGUAGE="JavaScript"> var javawsInstalled = 0;  var javaws142Installed=0;var javaws150Installed=0;var javaws160Installed = 0;isIE = "false"; if (navigator.mimeTypes && navigator.mimeTypes.length) {    x = navigator.mimeTypes['application/x-java-jnlp-file'];    if (x) {       javawsInstalled = 1;       javaws142Installed=1;      javaws150Installed=1;      javaws160Installed = 1;   } } else {    isIE = "true"; } </SCRIPT> 
  This script looks at the navigator.mimeTypes object and the navigator.mimeTypes.length var to decide if the browser is Netscape or IE. Iflength is 0, it is assumed the browser is IE, as with IE thenavigator.mimeTypes array is defined but always empty. If length is non-zero, then the browser is assumed to be Netscape and the JNLP MIME type is checked to see if it exists on Netscape. If so, javawsInstalled, javaws142Installed, javaws150Installed andjavaws160Installed are all set to 1. With Netscape it is not possible to determine which particular version of Java Web Start is installed, so all four variables are set to 1.
  这个脚本看起来像一个导航。通过mimeTypes对象和navigator.mimeTypes.length值来决定浏览器是Netscape还是IE。如果长度为0,我们假设浏览器是IE,如果是IE那么navigator.mimeTypes数组总是空的。如果长度不为空,那么浏览器是Netscape,然后检查是否存JNLP MIME类型。如果存在将 javawsInstalled, javaws142Installed, javaws150Installedjavaws160Installed的值设为1。因为Netscape无法确定安装了那个特定版本的Java Web Start,因此所有的这四个值被设为1。

Detecting if Java Web Start is installed on IE, and if so, the version number

The above JavaScript should be followed by a VBScript that sets variables related to Internet Explorer browers:

<SCRIPT LANGUAGE="VBScript">on error resume nextIf isIE = "true" Then  If Not(IsObject(CreateObject("JavaWebStart.isInstalled"))) Then     javawsInstalled = 0  Else     javawsInstalled = 1  End If  If Not(IsObject(CreateObject("JavaWebStart.isInstalled.1.4.2.0"))) Then     javaws142Installed = 0  Else     javaws142Installed = 1  End If   If Not(IsObject(CreateObject("JavaWebStart.isInstalled.1.5.0.0"))) Then     javaws150Installed = 0  Else     javaws150Installed = 1  End If    If Not(IsObject(CreateObject("JavaWebStart.isInstalled.1.6.0.0"))) Then     javaws160Installed = 0  Else     javaws160Installed = 1  End If  End If</SCRIPT>
  This VBScript is executed if the variable isIE from the preceeding JavaScript is"true"; i.e., if the end-user's browser is Internet Explorer. This script instantiates theisInstalled COM object in JavaWebStart.dll, and this object determines four things:

  若果前面的JavaScript中的isIE的值为True,那么这个VBScript被执行。i.e.,如果在IE浏览器的最后,这段脚本实例化JavaWebStart.dll中已经安装的sInstalled COM对象,这个对象会做如下四件事:

  • whether the client machine has any version of Java Web Start installed;
  • whether the client machine has version 1.2 of Java Web Start installed;
  • whether the client machine has versions 1.4.2 of Java Web Start installed;
  • whether the client machine has versions 1.5.0 of Java Web Start installed.
  • whether the client machine has versions 1.6.0 of Java Web Start installed.

  After the above two scripts have been executed, the variables javawsInstalled, javaws142Installed, javawsInstalled150 and javawsInstalled160 will be set to either 1 or 0, as follows:

  在上述两个脚本已被执行后, javawsInstalled, javaws142Installed, javawsInstalled150 和javawsInstalled160的值会被置为1或0,如下:

Browser

 

javawsInstalled

javaws142Installed

javaws150Installed

javaws160Installed

Internet Explorer

1 if any version of Java Web Start is installed; 0otherwise.

1 if Java Web Start 1.4.2 is installed; 0 otherwise.

1 if Java Web Start 1.5.0 is installed; 0 otherwise.

1 if Java Web Start 1.6.0 is installed; 0 otherwise.

Netscape Navigator

1 if any version of Java Web Start is installed; 0otherwise.

1 if any version of Java Web Start is installed; 0otherwise.

1 if any version of Java Web Start is installed; 0otherwise.

1 if any version of Java Web Start is installed; 0otherwise.

Launching the application if Java Web Start is Installed—or providing a link for auto-install or general download page

An additional JavaScript can be used to decide whether to(一个额外的JavaScript脚本可以被用来决定如何做):

  • provide a link to the application's jnlp file (i.e., Java Web Start is installed);
  • initiate auto-download of JRE 6.0, which includes Java Web Start (i.e., Java Web Start is not installed and the user is running IE on Windows);
  • or provide a link to the general download page for the 6.0 JDK/JRE (i.e., Java Web Start is not installed and the user is not running IE on Windows).

The following JavaScript handles these scenarios:

<script language="JavaScript">/* Note that the logic below always launches the JNLP application *if the browser is Gecko based. This is because it is not possible *to detect MIME type application/x-java-jnlp-file on Gecko-based browsers.  */if (javawsInstalled || (navigator.userAgent.indexOf("Gecko") !=-1)) {    document.write("<a href=http://www.MySite.com/app.jnlp>Launch         the application</a>");} else {    document.write("Click ");    document.write("<a href=http://java.sun.com/PluginBrowserCheck?        pass=http://www.MySite.com/download.html&        fail=http://java.sun.com/javase/downloads/ea.jsp>here</a> ");    document.write("to download and install JRE 5.0 and         the application.");}</SCRIPT>

Notes(注意:):

  1. The script only uses javawsInstalled—not javaws142Installedor javaws150Installedor javaws160Installed.
  2. The line breaks following '?' and '&' are for readability purposes only; in an actual script there should be no breaks in the href string.

  If javawsInstalled is 1, indicating that Java Web Start is already available on the client, then the script provides a link to the application's jnlp file. If Java Web Start is not installed on the client, the script instead provides a link to the PluginBrowserCheck program on the java.sun.com web site.PluginBrowserCheck checks whether the client uses Internet Explorer on a Microsoft Windows platform. If so,PluginBrowserChecksends the user to the auto-install page http://www.MySite.com/download.html. (See the next section, Creating an auto-install page, for how to create an auto-install page for IE running on Windows.) IfPluginBrowserCheckdetermines the user is not using Internet Explorer on Microsoft Windows, the user is redirected to the 6.0 JRE general download page on java.sun.com.

  如果javawsInstalled 是1,就说明Java Web Start是可以使用的,然后脚本提供一个链接到应用程序的jnlp文件的链接。如果Java Web Start没有在客户端安装,脚本会提供一个链接到java.sun.com网站上的PluginBrowserCheck程序的链接。PluginBrowserCheck检查客户端是否是否使用的是Windows平台的IE浏览器。如果是,PluginBrowserCheck将会跳转到自动安装页面http://www.MySite.com/download.html( Creating an auto-install page)。如果PluginBrowserCheck 判断用户不是使用IE浏览器,会自动跳转到 java.sun.com.网站中6.0 JRE下载页面。

Creating an auto-install page

  The download.html file should be staged on the server side. It contains specialOBJECT andPARAM tags that will download to the client an auto-installer for JRE 6.0 .Along with Java Web Start, an ActiveX control will be downloaded to the client. The ActiveX control will launch the application using the newly installed Java Web Start. Here is a sampledownload.html file:

  download.html下载页面应该在服务器上。其包含特殊的OBJECTPARAM 标签,因而会下载自动安装的JRE6.0到客户端。随着java web start,ActiveX控件将被下载到客户端。ActiveX控件将使用新安装的java web start启动应用程序。下面是一个简单的download.html文件:

<HTML><BODY><OBJECT codebase="http://java.sun.com/update/1.6.0/jinstall-6-windows-i586.cab#Version=6,0,0,0" classid="clsid:5852F5ED-8BF4-11D4-A245-0080C6F74284" height=0 width=0><PARAM name="app" value="http://www.MySite.com/app.jnlp"><PARAM name="back" value="true"><!-- Alternate HTML for browsers which cannot instantiate the object --><A href="http://java.sun.com/javase/downloads/ea.jsp">Download Java Web Start</A></OBJECT></BODY></HTML>
The OBJECT tag fetches a .cab file that contains an auto-installer for JRE 6.0.
The URL:

http://java.sun.com/update/1.6.0/jinstall-6-windows-i586.cab
will return the latest update release available for the Java SE 6 release.
  The string: Version=6,0,0,0 will be used to compare with the wsdetect.dll version, which is registered with the CLSID above. If the local machine has the dll installed and the version is greater than or equal to the Version specified, we will just load the dll in the local machine. Otherwise it will download and install Java from the codebase specified.
  The PARAM tags specify the location of the application's jnlp file so that it may be automatically launched after the JRE is installed on the client.
  app: Once the Java Web Start Active-X control is installed/loaded, it will invoke Java Web Start to launch the application specified by this URL.
  back: This controls the behavior of the browser after launching the application. It can remain on the current page (download.html in this case) or navigate back to the previous page.
For issues relating to application development see the next chapter, Application Development Considerations.

2.4 Application Development Considerations

Introduction

  Developing applications for deployment with Java Web Start is generally the same as developing stand-alone applications for the Java(TM) Platform Standard Edition. For instance, the entry point for the application is the standardpublic static void main(String[] argv).

  开发通过Java Web Start部署的应用于一般开发的JavaSE单机应用一样。例如,应用程序的入口为标准的public static void main(String [] argv)

  However, in order to support Web deployment—automatic download and launching of an application—and to ensure that an application can run in a secure sandbox, there are some additional considerations:

  然而为了支持Web部署时能够自动下载和运行程序,并且确保应用程序可以在一个安全的沙箱中,我们需要额外考虑一些问题:

  • An application must be delivered as a set of JAR files.
  • All application resources, such as files and images must be stored in JAR files; and they must be referenced using the getResource mechanism in the Java(TM) Platform Standard Edition (see below).
  • If an application is written to run in a secure sandbox, it must follow these restrictions:
    • No access to local disk.
    • All JAR files must be downloaded from the same host.
    • Network connections are enabled only to the host from which the JAR files are downloaded.
    • No security manager can be installed.
    • No native libraries may be used.
    • Limited access to system properties. The application has read/write access to all system properties defined in the JNLP File, as well as read-only access to the same set of properties that an Applet has access to.

Some of these restrictions can be overcome by the use of JNLP API to access the file system and other system resources.

访问文件系统和其他系统资源这些限制可以克服通过JNLP API的使用。

  • An application is allowed to use the System.exit call.
  • An application that needs unrestricted access to the system will need to be delivered in a set of signed JAR files. All entries in each JAR file must be signed.

Retrieving Resources from JAR files

  Java Web Start only transfers JAR files from the Web server to the client machine. It determines where to store the JAR files on the local machine. Thus, an application cannot use disk-relative references to resources such as images and configuration files.
  Java Web Start只将JAR文件从Web服务器下载到到客户端。并决定在本机的哪里存储这些JAR文件。因此,应用程序不能使用磁盘相对参考资源,如图片和配置文件。
  All application resources must be retrieved from the JAR files specified in theresourcessection of the JNLP file, or retrieved explicitly using an HTTP request to the Web server.Storing resources in JAR files is recommended, since they will be cached on the local machine by Java Web Start.
  所有的应用程序的资源必须从在JNLP文件的资源部分指定的JAR文件来检索,或检索Web服务器通过HTTP请求明确指定的。当我们通过Java Web Start缓存下来时,JAR包中的资源是可以利用的。

The following code example shows how to retrieve(检索) images from a JAR file:

// Get current classloaderClassLoader cl = this.getClass().getClassLoader();// Create iconsIcon saveIcon  = new ImageIcon(cl.getResource("images/save.gif"));Icon cutIcon   = new ImageIcon(cl.getResource("images/cut.gif"));...
The example assumes(假设) that the following entries(词条) exist in one of the JAR files for the application:
images/save.gifimages/cut.gif

Accessing the Client Using JNLP API

JNLP API can be used to access the client's file system and other resources.See the following topics for more information about using JNLP API to access the client:

JNLP API可用于访问客户端的文件系统和其他资源。看下面的主题,来获取更多关于使用JNLP API访问客户端的更多信息。

  • JNLP API Examples
  • Accessing Client the Using JNLP API (Topic in theDeployment Trail of the Java Tutorials. Although the sample shown is an applet, the information applies to Java Web Start applications also.)

Security and Code Signing

Java Web Start addresses the security issues(Java Web Start解决安全问题):

  • Protecting users against malicious code (intentional & unintentional) that may affect local files;
  • 保护用户免受恶意代码(故意和无意的)可能会影响本地文件。
  • Protecting enterprises against code that may attempt to access or destroy data on networks.
  • 保护企业免受可能试图访问或销毁网络上的数据的代码。

  Applications launched with Java Web Start are, by default, run in a restricted environment where they have limited access to local computing resources, such as storage devices and the local network. In this sandbox environment, Java Web Start can guarantee that a downloaded and potentially untrusted application cannot compromise the security of the local files or the network.
  默认情况下,通过Java Web Start运行的应用程序运行在一个受限制的环境下,被阻止访问本地计算机资源,例如:存储设备和本地网络。在沙箱中,Java Web Start可以保证下载的和潜在的不受信任的应用程序不牵连到本地文件或网络的安全。
  An additional security feature supported by Java Web Start is digital code signing. If an application being invoked is delivered in one or more signed JAR files, Java Web Start will verify that the contents of the JAR file have not been modified since they were signed. If verification of a digital signature fails, Java Web Start will not run the application, since it may have been compromised by a third-party.
  Java Web Start的数字代码签名提供了一个额外的安全特性。如果一个应用被一个或多个签名的JAR文件调用,Java Web Start会验证这个被调用的JAR文件有没有被签名的JAR文件所修改。如果一个数字签名验证失败,Java Web Start将不会运行这个应用程序,因为他可能已被一个第三方所更改。

  The support for code signing is important for both users and for application service providers. This service makes it possible for users to verify that an application comes from a trusted source. Because the application service provider signs the code, both can be ensured that no other party can impersonate the application on the Web. A signed application that is trusted by the user can also request additional system privileges, such as access to a local disk.
  代码签名的支持对于用户和应用程序提供商都很重要。此服务使用户可以验证应用程序来自可信源的应用程序。由于应用服务提供商对代码进行了签名,不仅可以确保在Web上没有地方可以模仿,而且一个由用户信任的签名应用程序也可以请求额外的系统权限,如访问本地磁盘。
  Java Web Start presents a dialog displaying the application's origin, based on the signer's certificate, before the application is launched. This allows the user to make an informed decision about whether or not to grant additional privileges to the downloaded code.

  Java Web Start会在应用程序启动时显示程序的来源,基于签名的证书。这就允许用户在是否授予下载的代码额外权限时做出明智的决定。

By including the following settings in the JNLP file, an application can request full access to a client system if all its JAR files are signed :
通过下面所列出的在JNLP文件中的设置,应用程序可以在其所有JAR文件都有签名的前提下访问客户端系统。

<security>   <all-permissions/></security>
  The implementation of code signing in Java Web Start is based on the security API in the core Java(TM) Platform Standard Edition. The Java 2 SE JRE 1.4.2 supports code signing with the SHA1withDSA and MD5withRSA algorithms.
  Java Web Start代码签名的实现是基于Java标准版的核心API的。Java 2 SE JRE 1.4.2 支持的代码签名使用了 SHA1withDSA and MD5withRSA加密算法。

  Developers sign code for use with Java Web Start in the same way as for Java Applets—by using the standard jarsigner tool from the Java(TM) Platform Standard Edition. The jarsigner tool documentation provides examples of how to sign code and create test certificates, and it discusses other issues related to signing.

  开发者对代码进行签名所使用的与使用Java(TM) Platform Standard Edition所提供标准的jarsigner工具进行签使用的是同样的方法。jarsigner工具的文档提供了关于如何给代码进行签名以及创建测试证书的示例,并且叶导轮了有关部署的其他问题。

Signing JAR Files With a Test Certificate

Here are the steps needed to sign a JAR file with a test certificate(证书):

  1. Make sure that you have an SDK 1.4.2 keytool and jarsigner in your path. These tools are located in the SDK bin directory.
  2. Create a new key in a new keystore asfollows:
    keytool -genkey -keystore myKeystore -alias myself
    You will get prompted for a information about the new key, such as password, name, etc. This will create the myKeystore file on disk.
  3. Then create a self-signed test certificate as follows:
    keytool -selfcert -alias myself -keystore myKeystore
    This will prompt for the password. Generating the certificatemay take a few minutes.
  4. Check to make sure that everything is okay. To list the contents of the keystore, use this command:
    keytool -list -keystore myKeystore
    It should list something like:
    Keystore type: jksKeystore provider: SUNYour keystore contains 1 entry:myself, Tue Jan 23 19:29:32 PST 2001, keyEntry,Certificate fingerprint (MD5):C2:E9:BF:F9:D3:DF:4C:8F:3C:5F:22:9E:AF:0B:42:9D
  5. Finally, sign the JAR file with the test certificate as follows:
    jarsigner -keystore myKeystore test.jar myself
    Repeat this step with all of your JAR files.

  Note that a self-signed test certificate should only be used for internal testing, since it does not guarantee the identity of the user and therefore cannot be trusted. A trust-worthy certificate can be obtained from a certificate authority, such asVeriSign or Thawte, and should be used when the application is put into production.

How to Encode JNLP Files

  Beginning with Java Web Start version 1.2, JNLP files may be encoded in any character encoding supported by the Java(TM) Platform Standard Edition. (See theJava(TM) Platform Standard Edition documentation for a list of supported encodings.)
  从Java Web Start 1.2 版本开始,JNLP文件可以在任何Java所支持的字符编码进行编码。(了解支持的字符集可以查看Java(TM) Platform Standard Edition documentation)
  To encode a JNLP file, specify an encoding in the XML prolog of that file. For example, the following line indicates that the JNLP file will be encoded in UTF-16.

  我们为JNLP文件指定编码的XML序言。例如,下面一行表示JNLP文件件采用的编码格式是UTF-16。

<?xml version="1.0" encoding="utf-16"?>
The XML prolog itself must be UTF-8-encoded.(注意:XML序言必须是UTF-8的编码格式)

Dynamic Download of HTTPS Certificates

  Beginning with 1.4.2, Java Web Start dynamically imports certificates in much the same way as browsers do. In order to make this work, Java Web Start now sets its own https handler, using the java.protocol.handler.pkgs system properties, to initialize defaults for SSLSocketFactory and HostnameVerifier. It sets the defaults withHttpsURLConnection.setDefaultSSLSocketFactory and HttpsURLConnection.setDefaultHostnameVerifier.
  从Java Web Start 1.4.2 版本之后,便支持想浏览器一样动态引入证书。。。
  If your application uses those two method, make sure they are called after the Java Web Start https handler is initialized, otherwise your custom handler will be replaced by the Java Web Start default handler. You can ensure that your own customizedSSLSocketFactory and HostnameVerifiter are used by doing either of the following:

  1. Installing your own https handler, which will completely replace the Java Web Start https handler;
  2. Calling HttpsURLConnection.setDefaultSSLSocketFactory or HttpsURLConnection.setDefaultHostnameVerifieronly after the first https url object is created, which will execute the Java Web Start https handler initialization code first.

For information on creating a download servlet see the next chapter, JnlpDownloadServlet Guide.

2.5 JnlpDownloadServlet Guide

——————>>>>后期补充

2.6 JNLP File Syntax

——————>>>>后期补充

2.7 JNLP API Examples

——————>>>>后期补充

三、后期版本的增强

3.1 Java Web Start enhancements in version 6

——————>>>>后期补充

3.2 Java Rich Internet Applications Enhancements in JDK 7

——————>>>>后期补充

&#8195&#8195

最后修改时间:2016年11月10日17:13:36

********************************************************************************结束语********************************************************************************************
  我在写这篇博客的时候也是一名初学者,有任何疑问或问题请留言,或发邮件也可以,邮箱为:577328725@qq.com,我会尽早的进行更正及更改。
在我写过的博客中有两篇博客是对资源的整理,可能对大家都有帮助,大家有兴趣的话可以看看!!
下载资料整理——目录:http://blog.csdn.net/fanxiaobin577328725/article/details/51894331
  这篇博客里面是我关于我见到的感觉不错的好资源的整理,里面包含了书籍及源代码以及个人搜索的一些资源,如果有兴趣的可以看看,我会一直对其进行更新和添加。
优秀的文章&优秀的学习网站之收集手册:http://blog.csdn.net/fanxiaobin577328725/article/details/52753638
  这篇博客里面是我对于我读过的,并且感觉有意义的文章的收集整理,纯粹的个人爱好,大家感觉有兴趣的可以阅读一下,我也会时常的对其进行更新。
********************************************************************************感谢********************************************************************************************

0 0