04-《Apache Tomcat 9 User Guide》之部署项目

1.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.html

部署是用于将Web应用程序(第三方WAR或您本身的自定义Web应用程序)安装到Tomcat服务器的过程当中的术语。java

Web application deployment may be accomplished in a number of ways within the Tomcat server.web

Web应用程序部署能够在Tomcat服务器中以多种方式完成。shell

  • Statically; the web application is setup before Tomcat is started
  • 静态; 在Tomcat启动以前设置Web应用程序
  • Dynamically; by directly manipulating already deployed web applications (relying on auto-deployment feature) or remotely by using the Tomcat Manager web application
  • 动态; 经过直接操做已部署的Web应用程序(依赖于自动部署 功能)或使用Tomcat Manager Web应用程序远程操做

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.apache

Tomcat管理器是一个能够交互使用(经过HTML GUI)或以编程方式(经过基于URL的API)来部署和管理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.tomcat

有许多方法能够执行依赖Manager Web应用程序的部署。Apache Tomcat为Apache Ant构建工具提供任务。 Apache Tomcat Maven插件 项目提供与Apache Maven的集成。还有一个名为Client Deployer的工具,能够从命令行使用它,并提供其余功能,例如编译和验证Web应用程序以及将Web应用程序打包到Web应用程序资源(WAR)文件中。服务器

2.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).session

静态部署Web应用程序不须要安装,由于Tomcat提供了开箱即用的功能。尽管Tomcat Manager手册中详细说明了某些配置,但Tomcat Manager的部署功能也不须要任何安装 。可是,若是您但愿使用Tomcat客户端部署程序(TCD),则须要安装。app

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-9.0.x-deployer.

TCD未与Tomcat核心发行版一块儿打包,所以必须从“下载”区域单独下载。下载一般标记为 apache-tomcat-9.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安装根目录的ANT_HOME环境值,以及指向Java安装的JAVA_HOME值。此外,您应该确保Ant的ant命令,而且Java javac编译器命令从您的操做系统提供的命令shell运行。

  1. Download the TCD distribution
  2. 下载TCD发行版
  3. The TCD package need not be extracted into any existing Tomcat installation, it can be extracted to any location. 
  4. 不须要将TCD包提取到任何现有的Tomcat安装中,它能够被提取到任何位置。
  5. Read Using the Tomcat Client Deployer
  6. 阅读使用 Tomcat客户端部署程序

3.A word on Contexts

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的概念 。Context是Tomcat称之为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.xmlbut this is now discouraged (although it currently still works).

为了在Tomcat中配置Context, 须要一个Context Descriptor。上下文描述符只是一个XML文件,它包含上下文的Tomcat相关配置,例如命名资源或会话管理器配置。在早期版本的Tomcat中,Context Descriptor配置的内容一般存储在Tomcat的主配置文件server.xml中,但如今不建议这样作(尽管它目前仍然有效)。

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知道如何配置上下文,并且其余工具(如Tomcat Manager和TCD)一般使用这些上下文描述符来正确执行其角色。

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.

(1)中的文件名为[webappname] .xml,但(2)中的文件名为context.xml。若是没有为Context提供Context Descriptor,Tomcat将使用默认值配置Context。

4.Deployment on Tomcat startup

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.

若是您对使用Tomcat Manager或TCD不感兴趣,那么您须要将Web应用程序静态部署到Tomcat,而后是Tomcat启动。您为此类部署部署Web应用程序的位置称为 appBase 每一个主机指定的位置。您能够将所谓的展开的Web应用程序(即非压缩的)复制到此位置,或压缩的Web应用程序资源.WAR文件。

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".

appBase仅当主机的deployOnStartup属性为“true”时,将在Tomcat启动时部署 由主机(默认主机为“localhost”)属性指定的位置中的Web应用程序(默认appBase为“$ CATALINA_BASE / webapps”)。

The following deployment sequence will occur on Tomcat startup in that case:

在这种状况下,Tomcat启动时将发生如下部署顺序:

  1. Any Context Descriptors will be deployed first.
  2. 将首先部署任何上下文描述符。
  3. Exploded web applications not referenced by any Context Descriptor will then be deployed. If they have an associated .WAR file in the appBase and it is newer than the exploded web application, the exploded directory will be removed and the webapp will be redeployed from the .WAR
  4. 若是Host autoDeploy 属性为“true”,则Host将尝试根据须要动态部署和更新Web应用程序,例如,若是将新的.WAR放入其中appBase。为此,主机须要启用后台处理,这是默认配置。
  5. .WAR files will be deployed
  6. 将部署.WAR文件

5.Deploying on a running Tomcat server

It is possible to deploy web applications to a running Tomcat server.

能够将Web应用程序部署到正在运行的Tomcat服务器。

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.

若是Host autoDeploy 属性为“true”,则Host将尝试根据须要动态部署和更新Web应用程序,例如,若是将新的.WAR放入其中appBase。为此,主机须要启用后台处理,这是默认配置。

autoDeploy  设置为“true”,运行Tomcat容许:

autoDeploy  set to "true" and a running Tomcat allows for:

  • Deployment of .WAR files copied into the Host appBase.
  • 部署.WAR文件复制到主机中appBase
  • Deployment of exploded web applications which are copied into the Host appBase.
  • 部署已复制到主机中的爆炸式Web应用程序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.
  • 从新部署已在提供新.WAR时从.WAR部署的Web应用程序。在这种状况下,将删除爆炸的Web应用程序,并再次展开.WAR。请注意,若是配置主机以使.WAR未展开且unpackWARs属性设置为“false”,则不会发生爆炸,在这种状况下,Web应用程序将简单地从新部署为压缩存档。
  • Re-loading of a web application if the /WEB-INF/web.xml file (or any other resource defined as a WatchedResource) is updated.
  • 若是更新了/WEB-INF/web.xml文件(或定义为WatchedResource的任何其余资源),则从新加载Web应用程序。
  • Re-deployment of a web application if the Context Descriptor file from which the web application has been deployed is updated.
  • 若是更新了部署Web应用程序的Context Descriptor文件,则从新部署Web应用程序。
  • Re-deployment of dependent web applications if the global or per-host Context Descriptor file used by the web application is updated.
  • 若是更新Web应用程序使用的全局或每主机上下文描述符文件,则从新部署从属Web应用程序。
  • 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.
  • 若是将上下文描述符文件(具备与先前部署的Web应用程序的上下文路径对应的文件名)添加到$CATALINA_BASE/conf/[enginename]/[hostname]/ 目录中,则从新部署Web应用程序 。
  • 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.
  • 若是删除了其文档库(docBase),则取消部署Web应用程序。请注意,在Windows上,这假定启用了反锁定功能(请参阅上下文配置),不然没法删除正在运行的Web应用程序的资源。

Note that web application reloading can also be configured in the loader, in which case loaded classes will be tracked for changes.

若是删除了其文档库(docBase),则取消部署Web应用程序。请注意,在Windows上,这假定启用了反锁定功能(请参阅上下文配置),不然没法删除正在运行的Web应用程序的资源。

6.Deploying using the Tomcat Manager

The Tomcat Manager is covered in its own manual page.

Tomcat Manager包含在本身的手册页中

7.Deploying using the Client Deployer Package

Finally, deployment of web application may be achieved using the Tomcat Client Deployer. This is a package which can be used to validate, compile, compress to .WAR, and deploy web applications to production or development Tomcat servers. It should be noted that this feature uses the Tomcat Manager and as such the target Tomcat server should be running.

最后,能够使用Tomcat Client Deployer实现Web应用程序的部署。这是一个包,可用于验证,编译,压缩到.WAR,以及将Web应用程序部署到生产或开发Tomcat服务器。应该注意,此功能使用Tomcat Manager,所以目标Tomcat服务器应该运行。

It is assumed the user will be familiar with Apache Ant for using the TCD. Apache Ant is a scripted build tool. The TCD comes pre-packaged with a build script to use. Only a modest understanding of Apache Ant is required (installation as listed earlier in this page, and familiarity with using the operating system command shell and configuring environment variables).

假设用户熟悉Apache Ant以使用TCD。Apache Ant是一个脚本化的构建工具。TCD预先打包了要使用的构建脚本。只须要对Apache Ant有必定的了解(本页前面列出的安装,熟悉使用操做系统命令shell和配置环境变量)。

The TCD includes Ant tasks, the Jasper page compiler for JSP compilation before deployment, as well as a task which validates the web application Context Descriptor. The validator task (class org.apache.catalina.ant.ValidatorTask allows only one parameter: the base path of an exploded web application.

TCD包括Ant任务,部署前用于JSP编译的Jasper页面编译器,以及验证Web应用程序上下文描述符的任务。验证器任务(类 org.apache.catalina.ant.ValidatorTask )仅容许一个参数:爆炸Web应用程序的基本路径。

The TCD uses an exploded web application as input (see the list of the properties used below). A web application that is programmatically deployed with the deployer may include a Context Descriptor in /META-INF/context.xml.

TCD使用爆炸的Web应用程序做为输入(请参阅下面使用的属性列表)。以部署程序编程部署的Web应用程序能够包括上下文描述符 /META-INF/context.xml

The TCD includes a ready-to-use Ant script, with the following targets:

TCD包含一个即用型Ant脚本,具备如下目标:

  • compile (default): Compile and validate the web application. This can be used standalone, and does not need a running Tomcat server. The compiled application will only run on the associated Tomcat X.Y.Z server release, and is not guaranteed to work on another Tomcat release, as the code generated by Jasper depends on its runtime component. It should also be noted that this target will also compile automatically any Java source file located in the /WEB-INF/classes folder of the web application.
  • compile(默认):编译并验证Web应用程序。这能够单独使用,也不须要运行Tomcat服务器。已编译的应用程序将仅在关联的 Tomcat XYZ服务器版本上运行,而且不保证能够在另外一个Tomcat版本上运行,由于Jasper生成的代码取决于其运行时组件。还应注意,此目标还将自动编译位于 /WEB-INF/classes Web应用程序文件夹中的任何Java源文件 。
  • deploy: Deploy a web application (compiled or not) to a Tomcat server.
  • deploy:将Web应用程序(已编译或未编译)部署到Tomcat服务器。
  • undeploy: Undeploy a web application
  • undeploy:取消部署Web应用程序
  • start: Start web application
  • start:启动Web应用程序
  • reload: Reload web application
  • reload:从新加载Web应用程序
  • stop: Stop web application
  • stop:中止Web应用程序

In order for the deployment to be configured, create a file called deployer.properties in the TCD installation directory root. In this file, add the following name=value pairs per line:

为了配置部署,请建立deployer.properties 在TCD安装目录root中调用的文件。在此文件中,每行添加如下name = value对:

Additionally, you will need to ensure that a user has been setup for the target Tomcat Manager (which TCD uses) otherwise the TCD will not authenticate with the Tomcat Manager and the deployment will fail. To do this, see the Tomcat Manager page.

此外,您须要确保已为目标Tomcat Manager(TCD使用)设置了用户,不然TCD将不会使用Tomcat Manager进行身份验证,部署将失败。要执行此操做,请参阅Tomcat Manager页面。

  • build: The build folder used will be, by default, ${build}/webapp/${path} (${build}, by default, points to ${basedir}/build). After the end of the execution of the compiletarget, the web application .WAR will be located at ${build}/webapp/${path}.war.
  • build:默认状况下,使用的构建文件夹 ${build}/webapp/${path}${build},默认状况下指向${basedir}/build)。在compile目标执行结束后,Web应用程序.WAR将位于${build}/webapp/${path}.war
  • webapp: The directory containing the exploded web application which will be compiled and validated. By default, the folder is myapp.
  • webapp:包含将被编译和验证的爆炸Web应用程序的目录。默认状况下,该文件夹是 myapp
  • path: Deployed context path of the web application, by default /myapp.
  • path:默认状况下,部署Web应用程序的上下文路径 /myapp
  • url: Absolute URL to the Tomcat Manager web application of a running Tomcat server, which will be used to deploy and undeploy the web application. By default, the deployer will attempt to access a Tomcat instance running on localhost, at http://localhost:8080/manager/text.
  • url:正在运行的Tomcat服务器的Tomcat Manager Web应用程序的绝对URL,将用于部署和取消部署Web应用程序。默认状况下,部署者将尝试访问在localhost上运行的Tomcat实例 http://localhost:8080/manager/text
  • username: Tomcat Manager username (user should have a role of manager-script)
  • username:Tomcat Manager用户名(用户应该具备manager-script的角色)
  • password: Tomcat Manager password.
  • password:Tomcat Manager密码。

      声明,本文内容来自于Apache基金会官网关于Tomcat项目的官方文档,本人在原文档内容基础上整理总结而得,中文翻译仅供参考,英语不还错的童鞋,能够直接去官方查看最新的官方文档哦!!!若是以为对你有帮助,不要忘了点赞,评论,转发哟!!!

相关文章
相关标签/搜索