A detailed explanation of Tomcat's four kinds of Web application deployment methods

Source: Internet
Author: User
Tags parent directory

There are four ways to deploy Web applications in Tomcat, briefly summarizing the following:

(1) Automatic deployment with Tomcat

(2) Using the console for deployment

(3) Add custom Web Deployment Files (%tomcat_home%\conf\catalina\localhost\appname.xml)

(4) Manually modify the%tomcat_home%\conf\server.xml file to deploy the Web application

The first way: Automatic deployment with Tomcat

Using Tomcat for automatic deployment is the simplest and most common way. If a Web application structure is d:\workspace\webapp\appname\web-inf\*, simply throw the webcontent-level AppName of a Web application directly into the%tomcat_home%\ WebApps folder, the system deploys the Web application directly to Tomcat. so here is no longer to repeat.

the second way: Using the console for deployment

If a WEB application structure is d:\workspace\webapp\appname\web-inf\*, Use the console for deployment as follows: into the Deploy area of Tomcat's manager console- Type "XXX" in the context path (optionally named)--at the war or Directory URL: type D:\workspace\WebApp\AppName (means to find a Web application under this path)--click the Deploy button.

then a folder named XXX will automatically appear under the% Tomcat_home%\webapps path, which is the contents of the D:\workspace\WebApp\AppName. Just the name is xxx (this is the result of the previous type XXX in the context path).

The fact that using the console for deployment is still the essence of using Tomcat's automated deployment.

the Third way: adding Custom Web Deployment Files

If a WEB application structure is d:\workspace\webapp\appname\web-inf\*, This deployment is a little more complicated, and we need to %tomcat_home%\conf Create a new folder under the path catalina--and then create a new localhost folder--Create a new XML file, add a two-tier directory and add the XML file:%tomcat_home%\conf\catalina\ Localhost\web applies the configuration file. XML, which is the configuration file that deploys the Web application. For example, we create a new %tomcat_home%\conf\catalina\localhost\xxx.xml that contains the following contents:

<context path= "/xxx" reloadable= "true" docbase= "D:\workspace\WebApp\AppName" workdir= "D:\workspace\WebApp\work" />

Attention:

(1) The Workdir in the above code indicates that the working directory to which the Web application was deployed (the servlet compiled by the JSP in the Web application can be found in it), and if you use eclipse as the IDE, Generally can be artificially set in the work directory of WebApp.

If Workdir is not indicated in the custom Web Deployment file Xxx.xml, the Web application is deployed by default under the %tomcat_home%\work\catalina\localhost\ directory under the new named XXX folder. (a servlet compiled by a JSP in a Web application can be found in it)

(2) The contextpath Specifies the virtual path name of the Web application. docBase Specifies the source path of the Web application to be deployed.

In fact, developers can deploy a Web application using the Tomcat plug-in eclipse to automatically create a deployment file without having to manually create the file, as follows:

1. Open eclipse--Open menu bar window Select Preference (Preferences)--select Tomcat on the left, as shown below:

2. You can see the declaration mode (context declaration pattern) highlighted in the previous illustration to choose to deploy the Web application in the form of a custom deployment file added to context files-and then contexts Directory to specify the parent of the above file (ie %tomcat_home%\conf\catalina\localhost )--click Apply or OK.

3. Finish the above steps, then select the Web Item right click Properties--Select Tomcat on the right, as shown in the following figure:

4. Check the checkbox before "is a Tomcat project" to associate the item to Tomcat.

Enter XXX in the context name, that is, the Web application custom deployment file name and the context path name.

In subdirectory to set as Web application root (optional), fill in the actual path of the Web application that you want to deploy (that is, the Web-inf parent directory).

Note: Eclipse automatically sets the Workdir to Workspace\webapp\work.

This automatically creates the %tomcat_home%\conf\catalina\localhost\xxx.xml file. Start Tomcat to deploy the Web application automatically.

Fourth Way: Manually modify the%tomcat_home%\conf\server.xml file to deploy the Web application

This method opens the %tomcat_home%\conf\server.xml file and adds the following elements to it:

<context docbase= "D:\workspace\WebApp\AppName" path= "/xxx" debug= "0" reloadable= "false"/>

Then start Tomcat.

Of course, if you use Eclipse, the settings in Eclipse also change: Open menu bar window Select Preference (Preferences)--tomcat--on the left to see the highlighted context in the above picture declaration Mode (Context declaration mode), choose to deploy the Web application as a server.xml file.

Start Tomcat.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.