There are two ways to deploy Java Web applications in Tomcat: Static deployment and dynamic deployment.
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:
1, copy the Petweb directory to $catalina_home\webapps, and then start the server on it. This method is relatively simple, the access address is as follows: http://localhost:8080/PetWeb/
2, this way can not necessarily copy Petweb directory to WebApps, directly in the f:\ deployment. To do this, change the $catalina_home\conf\server.xml file and add the <Context> tag to the
<context docbase= "F:/petweb" reloadable= "false" path= "/pet"/>
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 is a path, you can use an absolute path, or you can use a relative path relative to the WebApps. The value of the Path property is the root address of the access. The access address is as follows: http://localhost:8080/Pet/
3, this way is similar to the second way, but not to add a context tag in the Server.xml file, but to add an XML file in the $catalina_home\conf\catalina\localhost, such as Pet.xml, the contents are as follows:
<context docbase= "F:/petweb" reloadable= "false"/> You may find that the second approach is similar, but the Path property is missing, and the server uses the name of the. Xml as the value of the Path property. The access address is as follows: http://localhost:8080/Pet/
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 a command prompt (Start-->run-->cmd)
2. Set the JDK environment variable (if the students I have taught will not be configured, don't say that sun teacher taught you)
3. After entering the F:\PetWeb file at the command prompt, type the following command:
Jar.. \pet.war * * This should have Pet.war file under F:\. Among them. Represents the parent directory of the current directory.
Deploying the Pet.war file is as simple as changing the docbase= "F:\PetWeb" to docbase= "F:\Pet.war" or just copying it to WebApps. Restarting the server will allow Pet.war to be deployed 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 unpacking in the following ways, configured as follows:
<context docbase= "F:/petweb" reloadable= "false" unpackwar= "false"/> Keep everyone waiting. Today we'll show you how to deploy Java Web applications in Tomcat5.5.9. The focus of this article is how to deploy, so let's not introduce how to develop a Web application and how to start a Tomcat server. We are not considering what development tools to use now, but you should have a Java Web application before practicing the examples described in this article. This article assumes that the root directory of the Web application is petweb.
There are two ways to deploy Java Web applications in Tomcat: Static deployment and dynamic deployment.
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:
1, copy the Petweb directory to keep everyone waiting. Today we'll show you how to deploy Java Web applications in Tomcat5.5.9. The focus of this article is how to deploy, so let's not introduce how to develop a Web application and how to start a Tomcat server. We are not considering what development tools to use now, but you should have a Java Web application before practicing the examples described in this article. This article assumes that the root directory of the Web application is petweb. and stored under the f:\.
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:
1, copy the Petweb directory to $catalina_home\webapps, and then start the server on it. This is a simpler approach, but the Web application must be in the WebApps directory. The access address is as follows:
http://localhost:8080/PetWeb/
2, this way can not necessarily copy Petweb directory to WebApps, directly in the f:\ deployment. To do this, change the $catalina_home\conf\server.xml file and add the <Context> tag to the
<context docbase= "F:/petweb" reloadable= "false" path= "/pet"/>
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 is a path, you can use an absolute path, or you can use a relative path relative to the WebApps. The value of the Path property is the root address of the access. The access address is as follows: http://localhost:8080/Pet/
3, this way is similar to the second way, but not to add a context tag in the Server.xml file, but to add an XML file in the $catalina_home\conf\catalina\localhost, such as Pet.xml, the contents are as follows:
<context docbase= "F:/petweb" reloadable= "false"/> You may find that the second approach is similar, but the Path property is missing, and the server uses the name of the. Xml as the value of the Path property. The access address is as follows: http://localhost:8080/Pet/
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 a command prompt (Start-->run-->cmd)
2. Set the JDK environment variable (if the students I have taught will not be configured, don't say that sun teacher taught you)
3. After entering the F:\PetWeb file at the command prompt, type the following command:
Jar.. \pet.war * * This should have Pet.war file under F:\. Among them. Represents the parent directory of the current directory.
Deploying the Pet.war file is as simple as changing the docbase= "F:\PetWeb" to docbase= "F:\Pet.war" or just copying it to WebApps. Restarting the server will allow Pet.war to be deployed 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 in the following way, configured as follows:
<context docbase= "F:/petweb" reloadable= "false" unpackwar= "false"/>
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 information about this file, refer to the security model for Java Web application
<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/should have seen a beautiful 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:
In context Path (option): Enter/pet
In the XML configration file URL, you specify an. xml document, for example, we create a pet.xml file under F:\, with the following content:
<context reloadable= "false"/>docbase do not have to write because it is filled in the next text box. Or more simply, this text box doesn't fill anything.
In the war or Directory URL: type F:\PetWet or F:\Pet.war, then click the Deploy button to see if you have seen your Web application, and the name is your context Path (option): Name.
If you have a simpler way of deploying a. War file, here's a select War file uploae Click Browse to select the. war files, and then click Deploy.
- This article is from: Linux Tutorial Network
Deploying Java Web Applications in tomcat