The Java Tutorials have been written for JDK 8.Java教程是为JDK 8编写的。Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available.本页中描述的示例和实践没有利用后续版本中引入的改进,并且可能使用不再可用的技术。See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases.有关Java SE 9及其后续版本中更新的语言特性的摘要,请参阅Java语言更改。
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.有关所有JDK版本的新功能、增强功能以及已删除或不推荐的选项的信息,请参阅JDK发行说明。
To deploy your Java Web Start application, first compile the source code, package it as a JAR file, and sign the JAR file.要部署Java Web Start应用程序,首先编译源代码,将其打包为JAR文件,并对JAR文件进行签名。
Java Web Start applications are launched by using the Java Network Launch Protocol (JNLP). Java Web Start应用程序是通过使用Java网络启动协议(JNLP)启动的。Hence, you must create a JNLP file to deploy your application.因此,必须创建一个JNLP文件来部署应用程序。
The Deployment Toolkit script contains useful JavaScript functions that can be used to deploy Java Web Start applications on a web page.部署工具包脚本包含有用的JavaScript函数,可用于在网页上部署Java Web Start应用程序。
If you are unfamiliar with these deployment technologies, review the Deployment In-Depth lesson before proceeding.如果您不熟悉这些部署技术,请在继续之前查看深入部署课程。
Here are some step-by-step instructions to package and deploy your application. 下面是一些打包和部署应用程序的分步说明。The Dynamic Tree Demo application is used to illustrate the deployment of Java Web Start applications. 动态树演示应用程序用于演示Java Web Start应用程序的部署。You might want to set up build scripts to execute some of the following steps.您可能需要设置构建脚本来执行以下一些步骤。
Click the following Launch button to launch the Dynamic Tree Demo application.单击下面的启动按钮启动动态树演示应用程序。
In the Dynamic Tree Demo application, the compiled classes are placed in the 在动态树演示应用程序中,编译的类被放置在build/classes/webstartComponentArch
directory.build/classes/webstartComponentArch
目录中。
For the DynamicTree Demo applet, create a file named 对于DynamicTree演示小程序,在mymanifest.txt
in the build/classes
directory, and add the Permissions
, Codebase
, and Application-Name
attributes. build/classes
目录中创建一个名为mymanifest.txt
的文件,并添加Permissions
、Codebase
和Application-Name
属性。The applet does not require access to the user's system resources, so use 小程序不需要访问用户的系统资源,因此使用sandbox
for the permissions. sandbox
获得权限。Use the domain from which you will load the sample for the code base, for example, 使用将从中加载代码库示例的域,例如myserver.com
. myserver.com
。Add the following attributes to the 将以下属性添加到mymanifest.txt
file.mymanifest.txt
文件中。
Permissions: sandbox Codebase: myserver.com Application-Name: Dynamic Tree Demo
Other manifest attributes are available to restrict an applet to using only trusted code, and to provide security for applets that need to make calls between privileged Java code and sandbox Java code, or have JavaScript code that calls the applet. 其他清单属性可用于限制小程序仅使用受信任的代码,并为需要在特权Java代码和沙盒Java代码之间进行调用的小程序提供安全性,或具有调用小程序的JavaScript代码。See the Enhancing Security with Manifest Attributes lesson to learn more about the manifest attributes that are available.有关可用的清单属性的更多信息,请参阅使用清单属性增强安全性课程。
mymanifest.txt
file that you created in the previous step. mymanifest.txt
文件中包含清单属性。For example, the following command creates a JAR file with the class files in the 例如,下面的命令创建了一个JAR文件,其中类文件位于build/classes/webstartComponentArch
directory and the manifest file in the build/classes
directory.build/classes/webstartComponentArch
目录,清单文件位于build/classes
目录。
% cd build/classes % jar cvfm DynamicTreeDemo.jar mymanifest.txt webstartComponentArch
See the Packaging Programs in JAR Files lesson to learn more about creating and using JAR files.有关创建和使用JAR文件的更多信息,请参阅JAR文件中的打包程序课程。
See the Signing JAR Files lesson for more information.有关更多信息,请参阅签名JAR文件课程。
If you want to use a signed JNLP file for security, create the JNLP file as described in the next step and include it in the JAR file before the JAR file is signed. 如果要使用签名的JNLP文件来实现安全性,请按照下一步中的描述创建JNLP文件,并在JAR文件签名之前将其包含在JAR文件中。See Signed JNLP Files in the Java Platform, Standard Edition Deployment Guide for information.有关信息,请参阅Java平台标准版部署指南中的签名JNLP文件。
Here is the JNLP file that is used to launch the Dynamic Tree Demo application. 下面是用于启动动态树演示应用程序的JNLP文件。Permissions are not requested for this application so it runs in the security sandbox. 此应用程序未请求权限,因此它在安全沙箱中运行。The source for dynamictree_webstart.jnlp
follows:dynamictree_webstart.jnlp
的来源如下:
<?xml version="1.0" encoding="UTF-8"?> <jnlp spec="1.0+" codebase= "https://docs.oracle.com/javase/tutorialJWS/samples/deployment/webstart_ComponentArch_DynamicTreeDemo" href="dynamictree_webstart.jnlp"> <information> <title>Dynamic Tree Demo</title> <vendor>Dynamic Team</vendor> </information> <resources> <!-- Application Resources --> <j2se version="1.7+" href="http://java.sun.com/products/autodl/j2se"/> <jar href="DynamicTreeDemo.jar" main="true" /> </resources> <application-desc name="Dynamic Tree Demo Application" main-class= "webstartComponentArch.DynamicTreeApplication" width="300" height="300"> </application-desc> <update check="background"/> </jnlp>
codebase
and href
attributes are optional when deploying Java Web Start applications that will run on at least the Java SE 6 update 18 release or later. codebase
和href
属性是可选的。codebase
and href
attributes when deploying Java Web Start applications that will run with previous releases of the Java Runtime Environment software. codebase
和href
属性,这些应用程序将与Java运行时环境软件的早期版本一起运行。In the example, the Dynamic Tree Demo application is deployed in 在本例中,动态树演示应用程序部署在JavaWebStartAppPage.html
.JavaWebStartAppPage.html
中。
<body> <!-- ... --> <script src= "https://www.java.com/js/deployJava.js"></script> <script> // using JavaScript to get location of JNLP // file relative to HTML page var dir = location.href.substring(0, location.href.lastIndexOf('/')+1); var url = dir + "dynamictree_webstart.jnlp"; deployJava.createWebStartLaunchButton(url, '1.7.0'); </script> <!-- ... --> </body>
If you are not sure whether your end users will have the JavaScript interpreter enabled in their browsers, you can deploy the Java Web Start application directly by creating a link to the JNLP file as follows:如果您不确定最终用户是否会在浏览器中启用JavaScript解释器,可以通过创建指向JNLP文件的链接直接部署Java Web Start应用程序,如下所示:
<a href="/absolute path to JNLP file/dynamictree_webstart.jnlp">Launch Notepad Application</a>
If you deploy the Java Web Start application with a direct link, you cannot take advantage of the additional checks that the Deployment Toolkit functions provide. 如果使用直接链接部署Java Web Start应用程序,则无法利用部署工具包功能提供的附加检查。See Deploying a Java Web Start Application in the Deployment In-Depth lesson for details.有关详细信息,请参阅深度部署课程中的部署Java Web Start应用程序。
For this example, place 对于本例,请将DynamicTreeDemo.jar
, dynamictree_webstart.jnlp
, and JavaWebStartAppPage.html
in the same directory on the local machine or a web server. DynamicTreeDemo.jar
、dynamictree_webstart.jnlp
和JavaWebStartAppPage.html
放在本地计算机或web服务器的同一目录中。A web server is preferred. To run from the local machine, you must add your application to the exception site list, which is managed from the Security tab of the Java Control Panel.最好是网络服务器。要从本地计算机运行,必须将应用程序添加到异常站点列表中,该列表由Java控制面板的“安全”选项卡管理。
Download source code for the Dynamic Tree Demo example to experiment further.下载Dynamic Tree演示示例的源代码以进行进一步实验。