There are generally two ways to deploy a Java Web application on a Tomcat server: static and dynamic
First, static deployment
A static deployment is the deployment of our Web application before the Tomcat server is started, and only when the Tomcat server is enabled can our Web application be accessed)
1. Automatic deployment with Tomcat
Copy the Web application to/usr/local/tomcat/webapps/and restart the Tomcat server, at which point the configuration file is configured with autodeploy= "True,tomcat start this will automatically load the Web App
2. Modify Server.xml File Deployment
The application can be placed in a separate directory
mkdir/webapps/
Vim/usr/local/tomcat/conf/server.xml
Add the following line
<context path ="/test" reloadable ="false" docBase ="/webapps"/ >
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/Test/
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.
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 Test.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:
-
path = "/test" docbase = "/webapps"
Debug ="0" privileged ="true" reloadable ="false" >
</Context>
The access address is as follows: http://localhost:8080/Test/
Ii. Dynamic Deployment
Dynamic deployment refers to the ability to deploy a Web application after the server starts without restarting the server. Dynamic deployment to use the server provided by the Manager.war file, if there is no $catalina_home/webapps/under the file, you must go to re-download Tomcat, or you will not be able to complete the following functions. To use the hypervisor, 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 security Model two )
<tomcat-users>
<role rolename= "Tomcat"/>
<role rolename= "Role1"/>
<role rolename= "manager"/>&NBSP;
<user username= "Coresun" password= "Coresun" roles= "manager"/>
<user username= "Tomcat" password= "Tomcat" roles= "Tomcat"/>&NBSP;
<user username= "Both" password= "Tomcat" roles= "Tomcat,role1"/>
</ Tomcat-users>
Then type the following address in the browser: http://localhost:8080/, you should see a Garfield. Click the Tomcat Manager link on the left to prompt for your user name and password, this article is Coresun , and you can see the following pages:
650) this.width=650, "src=" http://hi.csdn.net/attachment/201003/22/2504700_12692438796qfN.jpg "width=" height= "429" style= "padding:0px;margin:0px;vertical-align:top;border:none;"/>
(1) context Path (option): Enter/pet in
(2)XML configration file URLTo specify an. xml file, for example, we create a pet.xml file under f:/, with the following content: <context reloadable="false" / > 。DocBaseNo need 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, and then click the Deploy button to see if you have seen your Web application, the name is your context Path ( Option): the name in.
(4) If you have a simpler way of deploying a. War file, here's a Select War file upload Click Browse to select the. war files, and then click Deploy.
Let Tomcat run only the web app specified in Conf/server.xml
There are 2 ways to do this:
Implement one:
1) Place the Web app you want to deploy in a path other than WebApps and specify docBase in the corresponding context in Server.xml.
2) Delete all the folders in WebApps, and all the XML files under Conf/catalina/localhost.
Note: WebApps is the value of the appBase property of the Host element in Server.xml.
Implementation two:
modify Server.xml Host Attributes of the element, added or modified: = deployonstartup = Span style= "Padding:0px;margin:0px;color:rgb (255,0,0);" >autodeploy =
Meaning:
deployxml ="false" : do not deploy XML corresponding web app under Conf/catalina/localhost
Deployonstartup ="false" : When Tomcat starts, all Web apps under WebApps are not deployed
Autodeploy ="false" : Avoid using Tomcat to deploy the Web app under WebApps again when scanning for changes.
Note:
Tomcat in the WebApps directory can not be directly stored in a Web page format file, otherwise you cannot access the file, you must have a subdirectory to access the Web page file.
For example: We put index.html directly in the WebApps directory, http://localhost:8080/index.html through the browser is inaccessible to index.html. You must be webapps/petweb/index.html to access the index.html page through http://localhost:8080/petweb/index.html.
This article from "Alex article" blog, declined reprint!
Common methods for deploying Web applications on a tomcat server