A summary of the Tomcat deployment Web application approach

Source: Internet
Author: User

A summary of the Tomcat deployment Web application approach
There are two ways to deploy Java Web applications in Tomcat: Static deployment and dynamic deployment.

In the following $catalina_home refers to the Tomcat root directory.

First, static deployment
Static deployment means that we deploy our program before the server starts, and only after the server is started can our web application access it.

The following 3 ways can be deployed: (Take the maintain project as an example, the maintain directory assumes F:/maintain)

1. Using Tomcat to deploy automatically
Copy the maintain directory to $catalina_home/webapps and start the server, and the app will be loaded automatically when Tomcat starts.

The access address is as follows: http://localhost:8080/maintain/

This is a simpler approach, but the Web application must be in the WebApps directory. Tomcat's WebApps directory is the default app directory for Tomcat and will load all applications in this directory when the server is started.

2. Modify the Server.xml file deployment
This way, you can not copy the maintain directory to WebApps and deploy it directly in f:/. Here's how to change the $catalina_home/conf/server.xml file,

Find the following:

XML code:

<context Path = "/pet" reloadable = "false" DocBase = "F:/maintain" Workdir = "D:/mywebapps/emp"/>
Path: is the root address of the access, indicating the path of the access, as in the above example, access to the application address is as follows: http://localhost:8080/Pet/

Reloadable: Indicates that the class package can be loaded automatically at run time under the classes and Lib folders. where reloadable= "false" means that the server does not automatically load after the content in the application is changed, and this property is usually set to true during the development phase, which is easy to develop, and should be set to false in the release phase to increase the access speed of the application.

Docbase: Represents the path to the application, note the direction of the slash "/". Docbase can use absolute paths, or relative paths, relative to WebApps.

Workdir: Represents the drop address of the cache file

3. Add custom Web Deployment files (recommended, no need to restart Tomcat)
This approach is similar to Method 2, but instead of adding a context tag to the Server.xml file, add an XML file to the $catalina_home/conf/catalina/localhost. such as Pet.xml. Under the Tomcat installation directory Conf/catalina/localhost, there are three apps that Tomcat comes with, feel free to copy one of the XML files, then modify Docbase to point to your own application and rename the file name, Each parameter is described in the parameters of the <Context> tag in Method 2, or you can create a new XML file yourself. (Note that this file name will be used as the Path property value in the context, regardless of how the Path property value is set in the file), copy the following and modify the appropriate path.

XML code:

<context Path = "/pet" docBase = "F:/maintain"
debug = "0" privileged = "true" reloadable = "false" >
</Context>
The access address is as follows: http://localhost:8080/Pet/
Note: Web apps are deployed as. War files
The JSP program can be packaged into a war package placed in the directory, the server will automatically unlock the war package, and in this directory to generate a folder with the same name. A war package is a jar package with an attribute format that compresses all the contents of a Web program.

We just deployed the Petweb folder on the server, and we know that we can make the content of the Web application into a. War package, and then deploy it on the server. For packaging please refer to the following steps:
1. Open command Prompt (cmd)
2. Setting the JDK environment variable
3. After entering the project folder F:/petweb at the command prompt, type the following command: Jar CVF Pet.war */. (Note the last one.) ”)。 This should have the Pet.war file under F:/petweb. (You can also package to the specified place, the command is as follows: Jar CVF D:/pet.war */.) )

Deploying the Pet.war file is as simple as changing the Docbase = "F:/maintain" in the xml file to Docbase = "F:/pet.war" or simply copying it to the WebApps directory. Then restart the server to deploy Pet.war as a Web application.

If you're careful, you'll find that the server Pet.war the file, and a pet folder is generated under WebApps, and the contents of the Pet.war are copied into it. We can cancel the automatic decompression by setting the Unpackwar property in the XML configuration file to "false" in the following way.


This article is from "Dream Dreams" blog, please be sure to keep this source http://dreamy.blog.51cto.com/12471447/1890159

A summary of the Tomcat deployment Web application approach

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.