A summary of Tomcat deployment Web application methods

Source: Internet
Author: User
Tags file url java web
A summary of Tomcat Deployment Web application methods

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 programs before the server is started, and our web applications are accessible only after the server is started.

All of the following 3 ways can be deployed: (Take the Petweb project as an example, the Petweb directory is assumed to be f:/petweb)

1. automatic deployment with Tomcat

Copy the Petweb directory to $catalina_home/webapps, then start the server, and the application will be loaded automatically when Tomcat starts.

The visit address is as follows: http://localhost:8080/PetWeb/

This approach is simpler, but the Web application must be in the WebApps directory. Tomcat's WebApps directory is the tomcat default application directory that loads all applications under this directory when the server is started.

2. Modify Server.xml File Deployment

This way you can not necessarily copy Petweb directory to WebApps, directly in f:/deployment. The following method, change the $catalina_home/conf/server.xml file,

Find the following:

XML code: <context Path = "/pet" reloadable = "false" DocBase = "F:/petweb" Workdir = "d:/mywebapps/emp"/& Gt

Path: is the root address at the time of the visit, which indicates the path of the access; In the example above, 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 when the content in the application is changed, and this property is typically set to true during the development phase, easy to develop, and should be set to false during the publishing phase to increase the access speed of the application.

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

Workdir: Represents the placement address of a cached file

3. Add custom Web Deployment files (recommended, do not 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 Tomcat's own three applications, copy one of the XML files, and then modify the docbase point to your own application, and rename the file name, Refer to the parameters of the <Context> tag in Method 2, or you can create a new XML file yourself. (Note that this file name is the Path property value in the context, regardless of how the path attribute value in the file is set to be invalid), copy the following and modify the appropriate path.

XML code: <context Path = "/pet" docBase = "f:/petweb" debug = "0" privileged = "true" reloadable = "fa LSE " > </Context>

The visit address is as follows: http://localhost:8080/Pet/

Note: Web applications are deployed as. War Files

You can package a JSP program into a war package and place it in the directory, and the server will automatically unlock the war package and generate a folder with the same name in this directory. A war package is an attribute-formatted jar package that compresses all the contents of a Web application.

We have just deployed the Petweb folder to the server, and we know that the content of the Web application can be typed as a. War package and then deployed on the server. For packaging please refer to the following steps:
1, open the command prompt (CMD)
2. Set JDK environment variables
3. After entering the f:/petweb of the project folder at the command prompt, type the following command:jar CVF Pet.war * *. (Note the last one.) ”)。 This should have Pet.war files under the 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 very simple, change the Docbase = "F:/petweb" in the xml file to Docbase = "F:/pet.war" or simply copy it to the WebApps directory. You can 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 creates a pet folder underneath the WebApps, and then copies the contents of Pet.war to the inside. We can cancel the automatic decompression in the following way, set the Unpackwar property in the XML configuration file to "false".

second, dynamic deployment

Dynamic deployment means that a Web application can be deployed after the server is started without restarting the server. Dynamic deployment to use the Manager.war file provided by the server, if you do not have the file under $catalina_home/webapps/, you must download tomcat, otherwise you will not be able to complete the following functions. To use this manager you must first edit the $catalina_home/conf/tomcat-users.xml file as follows: (For more on this file, refer to the Java Web application's security Model II) <tomcat-users >
<role rolename= "Tomcat"/>
<role rolename= "Role1"/>
<role rolename= "Manager"/>
<user username= "Coresun" password= "Coresun" roles= "manager"/>
<user username= "Tomcat" password= "Tomcat" roles= "Tomcat"/>
<user username= "Both" password= "Tomcat" roles= "Tomcat,role1"/>
<user username= "Role1" password= "Tomcat" roles= "Role1"/>
</tomcat-users>

Then type the following address in the browser: http://localhost:8080/, you should see a Garfield cat. Click on the Tomcat Manager link on the left, prompt for username and password, this article is Coresun, then you can see the following page:

(1) Context Path (option): Enter/pet


(2) XML configration A. xml file in the file URL, for example, we create a pet.xml file under f:/, which reads as follows:<context reloadable = "false" / > . DocBase don't have to write, because you want to fill in the next text box. Or more simply, this text box doesn't fill anything.


(3) WAR or Directory URL: type F:/petwet or F:/pet.war in, and then click on the Deploy button to see if you have seen the Web application, the name is your context Path (option): Name.


(4) If you are deploying a. War file there is a simpler way, there is also a select War file upload click to browse to select the. war files, and then click Deploy.

let Tomcat run only the Web application specified in Conf/server.xml

There are 2 ways to do this:

Achieve one:

1 The Web application to be deployed is placed outside the WebApps path and specified in the Docbase in the corresponding context of server.xml.

2 Delete all the folders in the WebApps and conf/catalina/localhost all the XML files.
Note: WebApps is the value of the AppBase property of the Host element in Server.xml.

Realize two:

Modify the properties of the Host element in Server.xml, add or modify: Deployxml = "false" Deployonstartup = "false" Autodeploy = "false"

Meaning:
Deployxml = "false": do not deploy XML under conf/catalina/localhost corresponding Web application

Deployonstartup = "false": all Web applications under WebApps are not deployed when Tomcat is started

Autodeploy = "false": avoid tomcat to deploy Web apps under WebApps again when scanning for changes.

Note:

A file that cannot be directly stored in a Web page in the WebApps directory of Tomcat cannot access the file, and a subdirectory is required to access the Web page file.
For example: We put index.html directly in the WebApps directory, http://localhost:8080/index.html is inaccessible to index.html through the browser. And you have to webapps/petweb/index.html to be able to access the Index.html page through http://localhost:8080/petweb/index.html.

" Comprehensive reference to the free passage of the article"

1.http://lukas06.blog.sohu.com/112367177.html TOMCAT Deployment Web Application

Three ways to 2.http://blog.csdn.net/jierui001/archive/2009/05/11/4168872.aspx Tomcat deployment Web applications

3.http://ericxu131.javaeye.com/blog/175831 deployment of Java Web Applications in tomcat (turn)

4.http://secyaher.blog.163.com/blog/static/3895577200781495722337/the project into a war file and at 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.