Tomcat翻译--Tomcat Web Application Deployment(Tomcat中部署web应用)
原文:http://tomcat.apache.org/tomcat-7.0-doc/deployer-howto.html
Introduction(介绍)
Deployment is the term used for the process of installing a web application (either a 3rd party WAR or your own custom web application) into the Tomcat server.
【“部署”是用来表示在Tomcat服务器上安装一个web应用(或者第三方war包以及你自定义的web应用)的术语。】
Web application deployment may be accomplished in a number of ways within the Tomcat server.
【部署web应用在tomcat中有多种实现方式。】
Statically; the web application is setup before Tomcat is started
Dynamically; by directly manipulating already deployed web applications (relying on auto-deployment feature) or remotely by using the Tomcat Manager web application
The Tomcat Manager is a web application that can be used interactively (via HTML GUI) or programmatically (via URL-based API) to deploy and manage web applications.
【静态部署:在tomcat启动之前就安装好的web应用;】
【动态部署:通过直接操作或者通过tomcat manager远程操作已经部署好的web应用(依赖自动部署特性)。】
【tomcat manager本身就是一个web应用,你可以使用它来交互式或者编程式地管理你的web应用。】
There are a number of ways to perform deployment that rely on the Manager web application. Apache Tomcat provides tasks for Apache Ant build tool. Apache Tomcat Maven Plugin project provides integration with Apache Maven. There is also a tool called the Client Deployer, which can be used from a command line and provides additional functionality such as compiling and validating web applications as well as packaging web application into web application resource (WAR) files.
【你可以使用Manager应用,通过多种方式进行部署。Apache Tomcat提供了Apache Ant构建工具来执行部署;Apache Tomcat Maven Plugin提供了与Maven的集成;还有一个名为Client Deployer的工具,你可以通过命令行来使用,这个工具还提供了一些额外的功能,比如编译、验证、打包等。】
Installation(安装)
There is no installation required for static deployment of web applications as this is provided out of the box by Tomcat. Nor is any installation required for deployment functions with the Tomcat Manager, although some configuration is required as detailed in the Tomcat Manager manual. An installation is however required if you wish to use the Tomcat Client Deployer (TCD).
The TCD is not packaged with the Tomcat core distribution, and must therefore be downloaded separately from the Downloads area. The download is usually labelled apache-tomcat-7.0.x-deployer.
【静态部署web应用时,不需要在tomcat中安装任何东西,因为这是tomcat本身就提供的功能;也不需要在tomcat manager中安装任何东西,尽管tomcat manager的操作手册中提到了会需要一些配置。但如果你想使用tomcat client deployer(TCD)的话,则需要进行安装。tomcat核心发行版中没有包含TCD,因此你需要单独下载,下载链接一般会被标记为”apache-tomcat-7.0.x-deployer“。】
TCD has prerequisites of Apache Ant 1.6.2+ and a Java installation. Your environment should define an ANT_HOME environment value pointing to the root of your Ant installation, and a JAVA_HOME value pointing to your Java installation. Additionally, you should ensure Ant's ant command, and the Java javac compiler command run from the command shell that your operating system provides.
【TCD需要预装Apache Ant 1.6.2+和Java。你的环境变量中需要定义一个ANT_HOME环境变量,指向Ant的安装目录,以及一个JAVA_HOME环境变量,指向Java的安装目录。除此之外,还需要保证ant命令和javac命令可以在你的操作系统的命令行中正常运行。】
Download the TCD distribution【下载TCD发行版】
The TCD package need not be extracted into any existing Tomcat installation, it can be extracted to any location.
Read Using the Tomcat Client Deployer
【TCD包可以被解压到任何位置,而不需要被解压到Tomcat的安装目录中。你可以参考“Tomcat Client Deployer的使用”这一小节。]
A word on Contexts(Context概述)
In talking about deployment of web applications, the concept of a Context is required to be understood. A Context is what Tomcat calls a web application.
【在讨论web应用的部署之前,首先了解以下Context的含义。在tomcat中,一个Context就表示一个web应用。】
In order to configure a Context within Tomcat a Context Descriptor is required. A Context Descriptor is simply an XML file that contains Tomcat related configuration for a Context, e.g naming resources or session manager configuration. In earlier versions of Tomcat the content of a Context Descriptor configuration was often stored within Tomcat's primary configuration file server.xml but this is now discouraged (although it currently still works).
Context Descriptors not only help Tomcat to know how to configure Contexts but other tools such as the Tomcat Manager and TCD often use these Context Descriptors to perform their roles properly.
【在Tomcat中配置一个Context,需要一个Context Descriptor。Context Descriptor是一个包含Context的相关配置的XML文件,比如资源标识或者会话管理器配置。在早先的Tomcat版本中,Context Descriptor配置经常被放在server.xml文件中,但现在已经不鼓励这么做(尽管依然可以这么做)。】
【Context Descriptor不仅帮助Tomcat了解怎样配置Context,而且其他的一些工具,比如Tomcat Manager以及TCD,也经常使用这些Context Descriptor来执行它们的功能。】
The locations for Context Descriptors are:
1.$CATALINA_BASE/conf/[enginename]/[hostname]/[webappname].xml
2.$CATALINA_BASE/webapps/[webappname]/META-INF/context.xml
Files in (1) are named [webappname].xml but files in (2) are named context.xml. If a Context Descriptor is not provided for a Context, Tomcat configures the Context using default values.
【Context Descriptor存放的位置如下:】
【1.$CATALINA_BASE/conf/[enginename]/[hostname]/[webappname].xml】
【2..$CATALINA_BASE/webapps/[webappname]/META-INF/context.xml】
【(1)中的文件名是[webappname].xml,(2)中的文件名是context.xml。如果一个Context没有提供Context Descriptor,则Tomcat会为用缺省值配置Context。】
Deployment on Tomcat startup【在Tomcat启动时部署】
If you are not interested in using the Tomcat Manager, or TCD, then you'll need to deploy your web applications statically to Tomcat, followed by a Tomcat startup. The location you deploy web applications to for this type of deployment is called the appBase which is specified per Host. You either copy a so-called exploded web application, i.e non-compressed, to this location, or a compressed web application resource .WAR file.
The web applications present in the location specified by the Host's (default Host is "localhost") appBase attribute (default appBase is "$CATALINA_BASE/webapps") will be deployed on Tomcat startup only if the Host's deployOnStartup attribute is "true".
【如果不想使用Tomcat Manager或者TCD,那么可以将web应用静态部署到tomcat上,接着再启动tomcat。对于每一个指定的Host,web应用应该被部署在appBase目录下,你可以在appBase目录下部署未解压的.war文件或者解压后的web应用。】
【当Host的deployOnStartup属性为true时,位于Host(缺省值为“localhost”)中的appBase属性(缺省值为"$CATALINA_BASE/webapps")下的web应用将随tomcat的启动而被自动部署。]
The following deployment sequence will occur on Tomcat startup in that case:
Any Context Descriptors will be deployed first.
Exploded web applications not referenced by any Context Descriptor will then be deployed. Note that if an exploded web application has an associated .WAR file in the appBase, Tomcat will not detect if the associated .WAR has been updated while Tomcat was stopped and will deploy the exploded web application as is. The exploded web application will not be removed and replaced with the contents of the updated .WAR file.
.WAR files will be deployed
【tomcat启动时,部署按照以下步骤顺序执行:】
【首先部署的是Context Descriptor。然后部署Context Descriptor中没有涉及到的已解压的web应用。注意,如果一个已解压的web应用在appBase下有一个相对应的.war文件,则tomcat不会检测自从上次关闭后,该.war文件是否被更新,而只是部署该解压后的web应用。解压后的web应用不会被移除,也不会被更新后的.war文件的内容替换。最后被部署的是.war文件。】
总结:tomcat启动时部署顺序如下:
1.部署$CATALINA_BASE/conf/[enginename]/[hostname]/[webappname].xml以及$CATALINE_BASE/webapps/[webappname]/META-INF/context.xml;
2.部署appBase下已经被解压的web应用;
3.部署appBase下的.war文件。
注:
(1)部署appBase下的已解压web应用以及.war文件,指的是appBase/这一级目录,不包括其他的子目录,也就是说,除了appBase/这一级目录下的web应用以及.war文件会被自动部署之外,其他的web应用以及.war文件不会被自动部署(.war文件也不会被自动解压)
(2)静态部署时,如果存在一个已解压的web应用,以及一个同名的未解压的web应用,则tomcat不会检测到自动上次关闭后,该.war文件是否被更新,而只会部署解压后的web应用,不会部署.war文件。只有在tomat启动后,当.war文件被修改后,才会更新相应的解压的web应用,即热部署。
Deploying on a running Tomcat server(在tomcat运行时部署,即热部署)
It is possible to deploy web applications to a running Tomcat server.
If the Host autoDeploy attribute is "true", the Host will attempt to deploy and update web applications dynamically, as needed, for example if a new .WAR is dropped into the appBase. For this to work, the Host needs to have background processing enabled which is the default configuration.
【在tomcat运行时也可以部署web应用。】
【如果主机的autoDeploy属性被设置为true,那么该主机在需要时会尝试动态部署及更新web应用。比如,如果一个appBase中添加了一个新的.war文件,则该主机就会动态解压并部署该web应用。为了实现这个目的,主机必须有一个具有默认配置的后台进程】
autoDeploy set to "true" and a running Tomcat allows for:
Deployment of .WAR files copied into the Host appBase.
Deployment of exploded web applications which are copied into the Host appBase.
Re-deployment of a web application which has already been deployed from a .WAR when the new .WAR is provided. In this case the exploded web application is removed, and the .WAR is expanded again. Note that the explosion will not occur if the Host is configured so that .WARs are not exploded with a unpackWARs attribute set to "false", in which case the web application will be simply redeployed as a compressed archive.
Re-loading of a web application if the /WEB-INF/web.xml file (or any other resource defined as a WatchedResource) is updated.
Re-deployment of a web application if the Context Descriptor file from which the web application has been deployed is updated.
Re-deployment of dependent web applications if the global or per-host Context Descriptor file used by the web application is updated.
Re-deployment of a web application if a Context Descriptor file (with a filename corresponding to the Context path of the previously deployed web application) is added to the $CATALINA_BASE/conf/[enginename]/[hostname]/ directory.
Undeployment of a web application if its document base (docBase) is deleted. Note that on Windows, this assumes that anti-locking features (see Context configuration) are enabled, otherwise it is not possible to delete the resources of a running web application.
【autoDeploy设为true,允许tomcat在运行时执行以下操作:】
【部署放到appBase下的.war文件;】
【部署放到appBase下的解压的web应用;】
【如果解压的web应用在appBase目录下还有一个相对应的.war文件,且该.war文件被更新了,此时,原先的web应用被移除,更新后的.war文件会被再次解压并部署。需要注意的是,如果unpackWars属性被设置为false,则不会像前面所说的那样对.war文件进行解压并部署;】
【如果/WEB-INF/web.xml文件或者任何被WatchedResource元素指定的资源发生更新,则对应的web应用会被重新部署;】
【如果Context Descriptor文件中描述的web应用被更新了,则重新部署该web应用;】
【如果web应用使用的全局或者per-host的Context Descriptor文件被更新,则该web应用会被重新部署;】
【如果在$CATALINA_BASE/conf/[enginename]/[hostname]/目录下增加了一个Context Descriptor文件(文件名与先前部署的web应用的Context path相同),则该web应用被重新部署;】
【如果一个web应用的docBase被删除,则该web应用被卸载。注意,在windows下,该特性假设anti-locking特性已被设置,否则不允许删除运行中的web应用的资源;】