Java Web Developer: Three ways to deploy projects in Tomcat

Source: Internet
Author: User
Tags file url java web

Web development, how to deploy a project in Tomcat:

Note case

1, in the Conf directory to create a new Catalina\localhost directory, a new XML file in the directory , the name can be arbitrary, as long as and the current file name is not repeated on the line, the content of the XML file is:

<context path= "/qxmobile" docbase= "/usr/local/webroot/qxmobile"

Reloadable= "false" debug= "0"

Privileged= "true" >

</Context>

The file name of the XML must match the name of path.

2. Put it directly into the WebApps directory

Tomact's WebApps directory is the Tomcat default app directory, which loads all applications in this directory when the server is started. You can also package a JSP program into a war package placed 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 format of the jar package, it is to tell a Web program of all the content to be compressed. Specifically how to package, you can use the IDE environment of many development tools, such as Eclipse, NetBeans, ant, JBuilder, etc. You can also use cmd

Command: JAR-CVF Applicationname.war package.*

WebApps This default application directory can also be changed. Open the Server.xml file under Tomcat's Conf directory to find the following:

Unpackwars= "true" autodeploy= "true" xmlvalidation= "false" Xmlnamespaceaware= "false" >

The appbase can be modified.

3. Specify in Server.xml

In the Tomcat 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 create a context within the host tag as follows.

In Tomcat, under the Conf directory, add the,

<context paht= "/hello" docbase= "" debug= "0" privileged= "true" ></Context>

(1) path is a virtual path;

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/hello/

(2) Docbase is the physical path of the application;

(3) Workdir is the working directory of this application, which stores the files related to the application generated by the runtime;

(4) Debug is to set the debug level, 0 to provide the least information, 9 to provide the most information;

(5) When privileged is set to true, the Tomcat web app is allowed to use the servlet within the container

(6) Reloadable if True, Tomcat automatically detects changes in the application's/web-inf/lib and/web-inf/classes directories, automatically mounts new applications, and can change the application without restarting Tomcat. Implementing a hot Deployment antiresourselocking and antijarlocking hot deployment is a parameter that requires an article configuration, false by default to avoid updating a webapp, and sometimes Tomcat does not remove the old WebApp completely, Usually leaves a jar package under Web-inf/lib, which must be turned off to delete, which causes the automatic deployment to fail. Set to True,tomcat when you run the corresponding WebApp, the source and jar files of the response are copied to a temporary directory.

This method can define aliases, the server side runs the project name path, and the externally accessed URL uses the XML file name. This method is very convenient to hide the name of the project, some project names are fixed can not be replaced, but external access when you want to change a path, very effective.

note: Deleting a web app also deletes the corresponding context in the corresponding folder and Server.xml under WebApps, and also deletes the corresponding XML file in the Tomcat Conf\catalinal\localhost directory. Otherwise Tomcat will still go to configure and load ...

Two dynamic deployments
Login to the Tomcat Management console: http://localhost:8080/, enter your username and password to manage your app and publish it dynamically.
In context Path (option): Enter/yourwebname, which represents the access address of your app.
XML configration in the file URL to specify an XML file, for example, we create a hmcx.xml file under F:\, the content is as follows: <context reloadable= "false"/> where docbase don't have to write Because it is populated in the next text box. Or more simply, this text box does not fill anything, in the war or Directory URL: Type F:\HMCX, and then click on the Deploy button, you can see the Web application, the name of the context Path (option): The name of the.

If there is a simpler way to deploy the. War file, here's a select War file uploae Click Browse to select the. war files, and then click Deploy.

From the watercress: http://www.douban.com/note/326314892/

There are several ways Tomcat deploys web apps:

1. Copy your war file or your Web App folder (including all the contents of the Web) into the $catalina_base/webapps directory.
2. Create an XML fragment file that includes only the context content for your Web service and place the file in the $catalina_base/webapps directory. The web app itself can be stored anywhere on the hard drive. This context fragment provides a convenient way to deploy a web app, and you don't need to edit server.xml unless you want to change the default deployment features, and you don't need to restart Tomcat to install a new web App.
3.
with Method 2, just place the context fragment under the Catalina_base\conf\catalina\localhost directory. This method is more effective than the method 2>, The author after many experiments found that the method 2 is not as good as the latter method. The former repeatedly appeared system cannot open the situation.
4. Add a context fragment directly to the Server.xml </Host> before using this method, Tomcat automatically catalina_base\conf\catalina\ A file fragment is generated under the localhost directory. The method has the same effect as Method 3. This way you need to delete the root directory .


In addition, in order for Tomcat to run only the Web applications specified in Conf/server.xml, there are several 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:
1) Modify the properties of the host element in the Server.xml, add or modify: Deployxml= "false"
deployonstartup= "false" autodeploy= "false "
2) 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": Prevent Tomcat from deploying the Web App under WebApps again when scanning for changes.

Java Web Developer: Three ways to deploy projects in 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.