Deploy the Java Web Program (jar CVF *. War */.) War package in Tomcat

Source: Internet
Author: User
Tags file url

The basic conversion from: http://www.blogjava.net/ocean07000814/articles/331694.html

This article mainly describes how to deploy Java Web applications in Tomcat.Program. Because the focus is on how to deploy the service, we will not describe how to develop Web applications or start Tomcat servers, nor do we consider any development tools. In short, before proceeding with the examples mentioned in this article, you should have a Java Web application. This document assumes that the root directory of the Web application is helloproject. And stored in c: \ Documents ents and Settings \ Administrator \ workspace, directory structure

 

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

There are two ways to deploy Java Web applications in Tomcat: static deployment and dynamic deployment.

I. Static deployment
Static deployment refers to the deployment of our programs before the server starts. Our Web applications can only be accessed after the server starts. The following three methods can be deployed:
1. Copy the helloproject directory to $ catalina_home \ webapps, and then start the server. This method is the simplest method. The access address is as follows: http: // localhost: 8080/helloproject

2. In this way, you do not have to copy the helloproject directory to webapps and deploy it directly in C: \ Documents ents and Settings \ Administrator \ workspace.
Change the $ catalina_home \ conf \ Server. xml file and add the <context> label in the <Context docbase = "C: \ Documents and Settings \ Administrator \ workspace \ helloproject" reloadable = "false" Path = "/HP"/>
Reloadable = "false" indicates that when the content in the application changes, the server will not automatically load it. This attribute is usually set to true in the development stage for convenient development, set it to false in the release phase to speed up application access.
Docbase is the path where the project is stored. You can use absolute or relative paths relative to webapps. The value of the path attribute is the root address during access. The access address is as follows: http: // localhost: 8080/HP

Note: If the helloproject has a webcontent directory,

The following configurations can be used and the access path must correspond
<Context docbase = "C: \ Documents ents and Settings \ Administrator \ workspace \ helloproject" reloadable = "false" Path = "/HP"/> access address: http: // localhost: 8080/HP/webcontent
<Context docbase = "C: \ Documents and Settings \ Administrator \ workspace \ helloproject \ webcontent" reloadable = "false" Path = "/HPT"/> access address: http: /// localhost: 8080/HPT
<Context docbase = "C: \ Documents ents and Settings \ Administrator \ workspace \ helloproject" Path = "/helloproject" reloadable = "true"/> access address: http: // localhost: 8080/helloproject

In <content docbase = ".." Path = "..." Workdir = "..." /> Workdir is the directory released by JSP after deployment. You can specify it by yourself or not.

3. This method is similar to the second method, but instead of adding the context tag to the server. xml file, you can add an XML file to $ catalina_home \ conf \ Catalina \ localhost,
Such as HP. XML, the content is as follows: <context docbase = "C: \ Documents ents and Settings \ Administrator \ workspace \ helloproject" reloadable = "false"/> you may find that it is similar to the second method,
However, the path attribute is missing. In this way, the server uses the. xml name as the value of the path attribute. The access address is as follows: http: // localhost: 8080/HP

See *. War's explanation and deployment.
We just deployed the helloproject folder on the server. We know that we can pack the content of the Web application into a *. War package, and then deploy it on the server.
For more information about packaging, see the following steps:
1. Open a command prompt (START-> Run-> cmd)
2. Set JDK environment variables (skip this step if they are set)
3. Enter the c: \ Documents and Settings \ Administrator \ workspace \ helloproject file in the command prompt, and enter the following command: jar cvf pht. War */.
In this way, the PHT. War file should exist in the current directory. Where ".." indicates the parent directory of the current directory. Command Line and directory structure




Deploying the PHT. War file is very simple,
(1) Change docbase = "C: \ Documents ents and Settings \ Administrator \ workspace \ helloproject" to docbase = "C: \ Documents and Settings \ Administrator \ workspace \ helloproject \ PHT. war"
(2) You can copy it directly to webapps.
Restart the server to deploy PHT. War as a web application.
If you are careful enough, you will find that the server unlinks the PHT. War file and generates a PHT folder under webapps, and then copies the PHT. War content to it.
You can cancel the automatic unpackage as follows:
<Host name = "localhost" appbase = "webapps" unpackwars = "true" autodeploy = "true">
<! -- Change "unpackwars =" true "to" false "to" OK "->
<Context .... />

</Host>

Ii. dynamic deployment

Dynamic deployment means you can deploy Web applications after the server starts, instead of restarting the server.
The manager. War file provided by the server is used for dynamic deployment. If the file does not exist under $ catalina_home \ webapps \, you must download Tomcat again. Otherwise, the following functions cannot be completed.
To use this hypervisor, you must first edit the $ catalina_home \ conf \ tomcat-users.xml file (for more information about this file, see Java Web Application Security Model 2 ),
The content is as follows:
<Tomcat-users>
<Role rolename = "Tomcat"/>
<Role rolename = "role1"/>
<Role rolename = "manager"/> <! -- This is added by myself, and tomcat 7 is Manager-Gui -->
<User Username = "admin" Password = "admin" roles = "manager"/> <! -- This is added by myself, and tomcat 7 is Manager-Gui -->
<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, enter http: // localhost: 8080/in the browser and click the Tomcat Manager link, prompting you to enter the user name and password. This document is admin and you can see the following page:

At ------>

1. Context path (required): Enter/HP.
2. Specify a * in XML configration File URL *. XML file, for example, we create a pH under D. the content of the XML file is as follows: docbase does not need to be written because it is entered in the next text box.
or simply, this text box is left empty.
3. in war or directory URL: Type C: \ Documents ents and Settings \ Administrator \ workspace \ helloproject or C: \ Documents and Settings \ Administrator \ workspace \ helloproject \ PHT. you can use war, and then click deploy to see if your web application has been seen above. The name is the name in your context path (required.
4. If you deploy the *. War file in a simpler way, you can click Select war File Upload to browse and select *. War file, and then click deploy.

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.