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項目的官方文檔,本人在原文檔內容基礎上整理總結而得,中文翻譯僅供參考,英語不還錯的童鞋,能夠直接去官方查看最新的官方文檔哦!!!若是以爲對你有幫助,不要忘了點贊,評論,轉發喲!!!

相關文章
相關標籤/搜索