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.

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

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
  • 静态; 在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.

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.

有许多方法可以执行依赖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).

静态部署Web应用程序不需要安装,因为Tomcat提供了开箱即用的功能。尽管Tomcat Manager手册中详细说明了某些配置,但Tomcat Manager的部署功能也不需要任何安装 。但是,如果您希望使用Tomcat客户端部署程序(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-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项目的官方文档,本人在原文档内容基础上整理总结而得,中文翻译仅供参考,英语不还错的童鞋,可以直接去官方查看最新的官方文档哦!!!如果觉得对你有帮助,不要忘了点赞,评论,转发哟!!!

 

转载于:https://my.oschina.net/aibinxiao/blog/2249894

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值