Three ways to deploy projects in Java Web development tomcat

Source: Internet
Author: User

Under normal circumstances, the development mode needs to configure the virtual host, automatic monitoring, service port, list directory files, management of multiple sites and other functions

Preparatory work:

Package: Apache-tomcat-6.0.20.rar

Unzip the package to a partition of the hard drive and enter the%tomcat_home%/conf directory

One: Server.xml configuration

1. Configure the port and modify the Server.xml.

< Connector Port="protocol" = "http/1.1"connectiontimeout="20000" redirectport="8443"/>

2. Configure the virtual directory, configure the <Context></Context> class management virtual directory in the <Host></Host> tab

< Context path="/BradendocBase=" E:\www "/>

However, it is recommended to build an XML file under the%tomcat_home%/\conf\catalina\localhost directory with a virtual directory name, so you can build the TOMCAT6 version%tomcat_home%/\conf\ Catalina\localhost\braden.xml, the contents are as follows

< Context docBase="E:\www"/>

This is done by: Localhost/braden access to the E:/WWW directory, indicating that the virtual host configuration was successful

II: Context.xml configuration, modified to automatically load the Web. XML, automatically loaded class library, the content is as follows

<Context Reload="true" reloadable="true"> <!--Default set of monitored resources -- <Watchedresource>Web-inf/web.xml</Watchedresource> <!--Uncomment this to disable session persistence across Tomcat restarts - <!--<manager pathname= ""/> -- <!--Uncomment this to enable Comet connection tacking (provides events in session expiration as well as WebApp Lif ecycle) -- <!--<valve classname= "Org.apache.catalina.valves.CometConnectionManagerValve"/> -- </Context> 

Three: Web. XML configuration, modified to list all the files in the directory, the content is as follows

<Init-param> <param-name>Listings</param-name> <param-value>True</param-value> </Init-param> 

Four: Modify the Tomcat-users.xml, modify the Tomcat custom administrator, the content is as follows

<Tomcat-Users> <role rolename="Tomcat"/> <role rolename="Role1"/> <role rolename="Manager" /> <User username="Admin" Password="Admin" Roles="Tomcat,role1,manager"/> </Tomcat-users> 

Five, configure the Web application site, you need to change the file to Server.xml

    For example: Give E:\www\braden\mail to the Tomcat server management so that others can use www.braden.com to access the Web resources under the Mail directory

    1. Configure a host with a name www.braden.com in the Tomcat Server.xml file and set the Mail directory mapping default virtual-like directory

    < Host name="www.braden.com"appBase="e:\www"><Context  Path="/"docBase="E:\www\braden\mail"/></  Host>

    2. Add DNS host records, the local directly modify the host file: C:\WINDOWS\system32\drivers\etc\host)

    192.168.1.10 www.braden.com     

    3. Restart the Tomcat server and start IE access http://www.braden.com/

    The common configuration in the development model is roughly the case, and some of the specific needs are based on the actual



    The first of these methods : In the Conf directory in Tomcat, add the,
    <context path= "/hello" docbase= "D:\eclipse3.2.2forwebtools\workspace\hello\WebRoot" debug= "0" privileged= " True ">
    </Context>
    for the context node properties, you can see the relevant documentation in detail.

    The second method of: Copies the Web project files to the WebApps directory.

    The third method of: Very flexible, in the Conf directory, the new Catalina (note case) \localhost directory, create a new XML file in the directory, the name can be arbitrary, as long as the file name and the current files are not repeated, the content of the XML file is:
    <context path= "/hello" docbase= "D:\eclipse3.2.2forwebtools\workspace\hello\WebRoot" debug= "0" privileged= " True ">
    </Context>

    the 3rd method has the advantage of defining an alias. The server-side run project name is 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.

    2nd, 3 There are advantages, you can define some personality configuration, such as the configuration of data sources.

    There is also an article in detail

    1. Put it directly into the WebApps directory
    Tomcat's WebApps directory is the default app directory for Tomcat and will load all applications in this directory when the server is started. You can also package a JSP program into a war package and place it in a directory where the server automatically unlocks the war package and generates a folder with the same name in this directory. A war package is a jar package with an attribute format that compresses all the contents of a Web program. 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 the cmd command: JAR-CVF applicationname.war package.*;
    It can even be packaged in program execution:
    try{
    String strjavahome = System.getproperty ("Java.home");
    Strjavahome = strjavahome.substring (0,strjavahome.lastindexof (\)) + "\\bin\\";
    Runtime.getruntime (). EXEC ("cmd/c start" +strjavahome+ "Jar CVF hello.war c:\\tomcat5.0\\webapps\\root\\*");
    }
    catch (Exception e) {System.out.println (e);} WebApps This default application directory can also be changed. Open the Server.xml file under Tomcat's Conf directory to find the following:
    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.
    <context path= "/myapp" reloadable= "true" docbase= "D:\myapp" workdir= "D:\myapp\work"/>
    Where path is the virtual path, Docbase is the physical path to the JSP application, and Workdir is the working directory of the application, which stores the files that are generated for this application. 3. Create a context file
    In both of these ways, the Web application is loaded by the server and generates an XML file in the Tomcat Conf\catalina\localhost directory with the following content:
    <context path= "/admin" docbase= "${catalina.home}/server/webapps/admin" debug= "0" privileged= "true" ></ Context>
    As can be seen, the file describes an application's context information, its content and server.xml in the context information format is consistent, the file name is the virtual directory name. You can directly create an XML file that is placed in the Tomcat Conf\catalina\localhost directory. Examples are as follows:
    Note: Deleting a web App also deletes the corresponding context in the corresponding folder under WebApps and server.xml the Tomcat conf
    The corresponding XML file is deleted under the \catalina\localhost directory. Otherwise tomcat will still be configured to load ... 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. In this way, the root directory needs to be deleted. In addition, in order for Tomcat to run only the web app 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 under Conf/catalina/localhost corresponding Web App 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.


    Http://www.blogjava.net/braden/archive/2010/07/18/318949.html



    Methods for three deployment projects in Java Web development tomcat

    Related Article

    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.