Three ways to deploy Web apps to Tomcat

Source: Internet
Author: User

Tomcat as a servlet/jsp container (server) is very good, open source free, need to know that Tomcat is a Web server, which conforms to the SERVLET/JSP specification, but does not implement all Java EE specifications, so we should still standardize the argument, Call Tomcat a javaweb server, not a Java EE server

We use the IDE to deploy the Javaweb project is basically a one-click completion, which is the benefit of the IDE to us, but it is necessary to understand the details of the deployment project

To deploy the Javaweb app to Tomcat, you need to explicitly or implicitly define a tomcat context. In Tomcat, each tomcat context represents a Web application. So we will also be divided into implicit and explicit two ways to summarize

An explicit deployment

Explicit deployment is also divided into two ways:

    • Create an XML file under Tomcat's Conf/catalina/localhost directory
    • Add a context element to Tomcat's Conf/server.xml file
Way One

If you decide to create an XML file for each context (the first way), then the file name is important because the context path is derived from the name of the file. For example, a Demo1

The. xml file is placed in the Conf/catalina/localhost directory, then the context path of the application is Demo1, and the URL to access is: Http://localhost:8080/Demo1

This context file has only one line of code:

<? XML version= "1.0" encoding= "UTF-8" ?> <  docBase= "D:/demo1"  reloadable= "true"></Context  >

The docbase here is the required property, which defines the location of the application. The Reloadable property is optional, and if it exists and the value is true, any additions, reductions, or updates of the Java class file or other resource file in the program can be detected by Tomcat and reloaded by the application

When the context file is added to Tomcat's specified directory, Tomcat automatically loads the application. When this file is deleted, Tomcat automatically uninstalls the application

Mode two

Add a context element under the host tag in the Conf/server.xml file

<HostAppBase= "WebApps"Autodeploy= "true"name= "localhost"Unpackwars= "true">            <ContextPath= "/demo2"DocBase= "D:/demo1"reloadable= "true"></Context></Host>

The first way to be different is to define the context here to define the path property for the context path, the value of the Path property represents the name of the project to be accessed, the URL to be accessed is: Http://localhost:8080/Demo2

In general, it is not recommended to manage the context through Server.xml because the configuration will take effect only after you restart Tomcat after the modification. However, if you have multiple applications that require testing, it might be easier to use this approach because you can manage all your applications in one file at the same time

an implicit deploymentWay Three

Implicit deployment is so convenient that it is highly recommended to deploy your project in this way. Start the server by copying a war file or the entire application to Tomcat's WebApps (the Tomcat default deployment project location can be modified in the Server.xml file but not recommended) directory.

Three ways to deploy Web apps to 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.