4 ways Tomcat deploys web apps and deploying multiple apps

Source: Internet
Author: User

Original:

There are four ways to deploy Web apps in Tomcat, with a brief summary of:

(1) Automatic deployment with Tomcat

(2) Deploy with the console

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

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

The first way: use Tomcat to deploy automatically

Using the Tomcat auto-deployment approach is the simplest and most common way. If a Web application structure is D:\workspace\WebApp\appname\web-inf\*, simply place the webcontent level AppName of a Web application thrown directly into the%tomcat_home%\webapps folder, the Web app is deployed directly to Tomcat. so don't repeat it here.

Second way: Deploy with the console

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

and then in %tomcat_home%\webapps under the path will automatically appear a folder named XXX, the content is D:\workspace\WebApp\AppName content, but the name is xxx (this is the result of typing XXX in the context path earlier).

The essence of deployment using the console is still the automatic deployment of Tomcat.

Third Way: Increase your custom Web deployment file

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

[HTML]View Plaincopy
  1. <ContextPath="/xxx"reloadable="true"DocBase="D:\workspace\WebApp\AppName"Workdir="D:\workspace\WebApp\work"/>

Attention:

(1) The Workdir in the above code indicates the working directory that the Web app is deployed in (where the servlet compiled by the JSP in the Web app can be found), 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 app will be deployed by default under the %tomcat_home%\work\catalina\localhost\ Path Create a new folder under the name XXX. (The JSP compiled in the Web app can be found in the servlet)

(2)Context path Specifies the virtual path name of the Web App. docBase Specifies the source path of the Web app to be deployed.

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

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

2. You can see the highlighted context Declaration mode (Context declaration mode) in the Select to deploy the Web App in the form of a custom deployment file for context files-and then contexts In directory, specify the parent directory for the above file (that is, %tomcat_home%\conf\catalina\localhost )-click Apply or OK.

3. Complete the steps above, and then select the Web Project right-click Properties-Select Tomcat on the right, as shown in:

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

In context name, enter XXX, which is the Web App custom deployment file name and the context path name.

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

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

This automatically creates the %tomcat_home%\conf\catalina\localhost\xxx.xml file. Launch Tomcat to automatically deploy your Web App.

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

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

[HTML]View Plaincopy
  1. <ContextDocBase="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 the Menu bar window select Preference (Preferences)--select tomcat--on the left to see the highlighted context declaration Mode (Context declaration mode) Select to deploy the Web app as a server.xml file.



Deploy multiple Web Apps

Let's talk about how the local computer is implemented:

If you want to access two Web projects under a tomcat, you can do so by adding a virtual host.

The detailed steps are as follows:

1. Pack two items into Tomcat's WebApps directory;

2, modify the Tomcat Server.xml file, the original code is as follows:

Unpackwars= "true" autodeploy= "true"
Xmlvalidation= "false" Xmlnamespaceaware= "false" >

</Host>

Add the following code:

Unpackwars= "true" autodeploy= "true"
Xmlvalidation= "false" Xmlnamespaceaware= "false" >
<context path= "ROOT" docbase= "/root"/>
</Host>
Unpackwars= "true" autodeploy= "true"
Xmlvalidation= "false" Xmlnamespaceaware= "false" >
<context path= "" docbase= "/springmvcarchitect2"/>
</Host>

Note Two points: A, the original host needs to add a context tag, and path from the original empty into the project name, because the path of two host can not be empty at the same time, otherwise access error, the original project name is root.

b, add a new host, set the path in Docbase to the path of the second Web project, where/springmvcarchitect2,name is the virtual domain name, custom.


3, modify the machine's host file (different from the host tag above, is the system host file), add an IP map, for example, the added host name is myspring.com, add 127.0.0.1 to the system host file myspring.com


4, restart Tomcat, you can use localhost:8080 and myspring.com:8080 access to two Web projects, where the port is set to 8080, you can change.


5, the same can be extended to multiple Web projects, only need to configure multiple host to

Attached: Some items such as the Jfinal framework default project under Root, so the war package cannot be placed under the WebApps folder, which requires additional storage path such as E:\test

1, server.xml configuration file as follows

Unpackwars= "true" autodeploy= "true"
Xmlvalidation= "false" Xmlnamespaceaware= "false" >
<context path= "ROOT" docbase= "C:\tomcat\webapps\ROOT"/>
</Host>
Unpackwars= "true" autodeploy= "true" >
<valve classname= "Org.apache.catalina.valves.AccessLogValve" directory= "Logs"
prefix= "Localhost_access_log" suffix= ". txt"
pattern= "%h%l%u%t &quot;%r&quot; %s%b "/>
<context path= "" docbase= "E:\test\ROOT" reloadable= "false" crosscontext= "true"/>
</Host>

2. System Host configuration file

Add 127.0.0.1 New domain name

3. Restart Tomcat.


4 ways Tomcat deploys web apps and deploying multiple apps

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.