Tomcat dynamic deployment and static deployment

Source: Internet
Author: User
Tags file url java web tomcat
First, static deployment
1. Copy the Web project files directly into 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. So you can package the JSP program into a war package 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 an attribute-formatted jar package that compresses all the contents of a Web application. How to package, you can use the IDE environment of many development tools, such as Eclipse and so on. You can also use cmd command: JAR-CVF mywar.war myweb
WebApps This default application directory can also be changed. Open the Server.xml file under Tomcat's Conf directory and find the following:
Unpackwars= "true" autodeploy= "true"
Xmlvalidation= "false" Xmlnamespaceaware= "false" >
You can change the appbase.
2, in the server.xml specified
In Tomcat's configuration file, a Web application is a specific context that can be deployed by deploying a JSP application in a new context in Server.xml. Open the Server.xml file and build a context within the host tag, as follows.

In the Conf directory in Tomcat, add in the,<context path= "/hello" docbase= "d:\ workspace\hello\webroot" debug= "0" privileged= "true" >
</Context>
Or
<context path= "/myapp" reloadable= "true" docbase= "D:\myapp" workdir= "D:\myapp\work"/>
Or
<context path= "/sms4" docbase= "D:\workspace\sms4\WebRoot"/>

Description
Path is a virtual path;
DocBase is the physical path of the application;
Workdir is the working directory for this application, which stores the files that are generated by the runtime in connection with this application;

Debug is set to debug level, 0 means to provide the least information, 9 to provide the most information
When privileged is set to true, Tomcat Web applications are allowed to use the servlet in the container
Reloadable if True, Tomcat automatically detects changes in the application's/web-inf/lib and/web-inf/classes directories, automatically loads new applications, and can change applications without reloading tomcat to achieve hot deployment
Antiresourcelocking and antijarlocking hot deployments are parameters that need to be configured, and the default false avoids updating a certain webapp, and sometimes Tomcat does not completely remove the old WebApp, usually leaving the web-inf/ A jar package under Lib must shut down Tomcat to remove it, which causes automatic deployment to fail. Set to True,tomcat when running the corresponding WebApp, the corresponding source files and jar files are copied to a temporary directory.
3. Create a context file
In the Conf directory, create a new Catalina\localhost directory, a new XML file in the directory, the name can not be arbitrarily taken, and the path after the name of the same, according to the configuration of this path below, The name of the XML should be Hello (hello.xml), and the contents of the XML file are:
<context path= "/hello" docbase= "E:\workspace\hello\WebRoot" debug= "0" privileged= "true" ></Context>

The Tomcat takes an example as follows:
<context docbase= "${catalina.home}/server/webapps/host-manager"
Privileged= "true" antiresourcelocking= "false" antijarlocking= "false" >
</Context>
This example is from Tomcat, and the edited content is actually the same as the second way, where the XML file name is the access path, which hides the application's real name.
4. Note:
Deleting a Web application also deletes the corresponding context in the corresponding folder and Server.xml under WebApps, and deletes the corresponding XML file in Tomcat's Conf\catalina\localhost directory. Otherwise Tomcat will still go to configure and load ...
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 the $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 information about this file, refer to the Java Web Application security Model two

Then type the following address in the browser:
Http://localhost:8080/should have seen a nice Garfield. 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:

Enter/pet
XML configration file URL in the context Path to specify an. xml document, such as we create a pet.xml file under F:\, which reads as follows:
Docbase do not have to write, because in the next text box to fill in. Or more simply, this text box doesn't fill anything.
either type F:\PetWet or F:\Pet.war in the war or Directory URL: And then click on the Deploy button to see if you've seen the Web application, the name is your context Path (option): The name in.

If you have a simpler way to deploy a. war file, there is also a select War file uploae Click Browse to select the. war files, 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.