Documentation

The Java™ Tutorials
Hide TOC
Deploying Without Codebase在没有代码库的情况下部署
Trail: Deployment
Lesson: Deployment In-Depth
Section: Deployment Toolkit
Subsection: Deploying a Java Web Start Application

Deploying Without Codebase在没有代码库的情况下部署

Beginning in the Java SE 7 release, you do not have to specify an absolute path for the codebase attribute in the Java Web Start application's Java Network Launch Protocol (JNLP) file. 从Java SE 7版本开始,您不必在Java Web Start应用程序的Java Network Launch Protocol(JNLP)文件中为codebase属性指定绝对路径。You can develop and test your applications in different environments without having to modify the path in the codebase attribute. 您可以在不同的环境中开发和测试应用程序,而无需修改codebase属性中的路径。If no codebase is specified, the Java Web Start software assumes that the codebase is relative to the web page from which the Java Web Start application is launched.如果未指定代码库,Java Web Start软件会假定代码库与启动Java Web Start应用程序的网页相关。

The following functions of the Deployment Toolkit script can be used to deploy Java Web Start applications in a web page when the JNLP file does not contain the codebase attribute:当JNLP文件不包含codebase属性时,可以使用部署工具包脚本的以下功能在网页中部署Java Web Start应用程序:


Note: To run, Java Web Start applications deployed by using the previously specified functions require at least the Java SE 7 release. 要运行,使用之前指定的函数部署的Java Web Start应用程序至少需要Java SE 7版本。If the client does not have at least the Java SE 7 release, the functions instruct the user to install the required Java Runtime Environment (JRE) software before launching the Java Web Start application. 如果客户端至少没有Java SE 7版本,则函数会指示用户在启动Java Web Start应用程序之前安装所需的Java Runtime Environment(JRE)软件。

Function signature:函数签名: launchWebStartApplication: function(jnlp)

Parameter:参数:

jnlpThe path to the JNLP file containing deployment information for the Java Web Start application. 包含Java Web Start应用程序部署信息的JNLP文件的路径。This path can be relative to the web page in which the Java Web Start application is deployed.此路径可以相对于部署Java web Start应用程序的网页。

Usage:用法:

In the following example, the launchWebStartApplication function is invoked in the href attribute of an HTML anchor (a) tag.在以下示例中,在HTML锚定(a)标记的href属性中调用launchWebStartApplication函数。

The dynamictree_webstart_no_codebase.jnlp JNLP file is used to deploy the Dynamic Tree Demo application.dynamictree_webstart_no_codebase.jnlpJNLP文件用于部署动态树演示应用程序。

<script src="https://www.java.com/js/deployJava.js"></script>
<a href="javascript:deployJava.launchWebStartApplication('dynamictree_webstart_no_codebase.jnlp');">Launch</a>

The Java Web Start application is launched when the user clicks the resulting HTML link.当用户单击生成的HTML链接时,会启动Java Web Start应用程序。


Function signature:函数签名 createWebStartLaunchButtonEx: function(jnlp)

Parameter:参数:

jnlpThe path to the JNLP file containing deployment information for the Java Web Start application. 包含Java Web Start应用程序部署信息的JNLP文件的路径。This path can be relative to the web page in which the Java Web Start application is deployed.此路径可以相对于部署Java web Start应用程序的网页。

Usage:用法:

The following example shows the usage of the createWebStartLaunchButtonEx function.以下示例显示createWebStartLaunchButtonEx函数的用法。

The dynamictree_webstart_no_codebase.jnlp JNLP file is used to deploy the Dynamic Tree Demo application.dynamictree_webstart_no_codebase.jnlp JNLP文件用于部署动态树演示应用程序。

<script src="https://www.java.com/js/deployJava.js"></script>
<script> var jnlpFile = "dynamictree_webstart_no_codebase.jnlp";
    deployJava.createWebStartLaunchButtonEx(jnlpFile);
</script>

The Java Web Start application is launched when the user clicks the resulting Launch button.当用户单击生成的启动按钮时,将启动Java Web Start应用程序。

Open JavaWebStartAppPage_No_Codebase.html in a browser to view the Dynamic Tree Demo application that is deployed by using the functions described in this topic.在浏览器中打开JavaWebStartAppPage_No_Codebase.html,查看使用本主题中描述的功能部署的动态树演示应用程序。


Note: 

You can also launch the Java Web Start application at the system command prompt by invoking the javaws command with the complete url of the JNLP file as shown in the following code snippet.您还可以在系统命令提示符下启动Java Web Start应用程序,方法是使用JNLP文件的完整url调用javaws命令,如以下代码段所示。

javaws http://example.com/dynamictree_webstart_no_codebase.jnlp

Download source code for the Dynamic Tree Demo example to experiment further.


Previous page: Changing the Launch Button
Next page: Checking the Client JRE Software Version