Three ways to Tomcat deploy Javaweb programs __web

Source: Internet
Author: User
1, 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. You can also package a JSP program into a war package and place it in the directory, and the server will automatically unlock the war package and generate a folder with the same name in this directory. A war package is an attribute-formatted jar package that compresses all the contents of a Web application. How to package, you can use a number of development tools IDE environment, such as Eclipse, NetBeans, Ant, JBuilder, and so on. You can also use cmd
Command: JAR-CVF Applicationname.war package.*;
You can even package 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 and find the following:
Autodeloy= "true" xmlvalidation= "Falase" xmlnamespaceaware= "false" >


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.
<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, Workdir is the working directory of the application, and the runtime is the file generated for this application.


3. Create a context file
In both of these ways, when a Web application is loaded by the server, it generates an XML file in the Tomcat's Conf\catalina\localhost directory, which reads as follows:
<context path= "/admin" docbase= "${catalina.home}/server/webapps/admin"
debug= "0" privileged= "true" ></Context>
As you can see, the file describes the context information for an application, and its content is consistent with the format of the Server.xml context information, which is the name of the virtual directory. You can create such an XML file directly under Tomcat's Conf\catalina\localhost directory. Examples are as follows:
Note: Deleting a Web application also deletes the corresponding context in the WebApps under the Server.xml, and the Tomcat's Conf
Delete the corresponding XML file in the \catalina\localhost directory. Otherwise tomcat will still be configured to load the shore ...


Tomcat deployment Web applications are mainly in the following ways:

1. Copy your war file or your Web application folder (including all the content 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 put the file in the $catalina_base/webapps directory. The Web application itself can be stored anywhere on the hard disk. This context fragment provides a convenient way to deploy Web applications, you do not need to edit server.xml, unless you want to change the default deployment features, you do not need to restart Tomcat to install a new Web application.
3.
With Method 2, only the context fragment is placed in the Catalina_base\conf\catalina\localhost directory. This method is more effective than method 2>, After several experiments, the author found that the method 2 is not as good as the following method. The former system cannot be opened repeatedly.
4. By adding a context fragment directly to the Server.xml </Host>, Tomcat automatically catalina_base\conf\catalina\ A file fragment is generated under the localhost directory. method has the same effect as Method 3. This method requires the root directory to be deleted.


In addition, to allow Tomcat to run only the Web applications specified in Conf/server.xml, there are several ways to do this:
Achieve one:
1 The Web application to be deployed is placed outside the WebApps path and specified in the Docbase in the corresponding context of server.xml.
2 Delete all the folders in the WebApps and conf/catalina/localhost all the XML files.
Note: WebApps is the value of the AppBase property of the host element in Server.xml.
Realize two:
1 Modify the properties of the host element in 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 application
Deployonstartup= "false": when Tomcat starts, all Web applications under WebApps are not deployed
Autodeploy= "false": prevents Tomcat from WebApps the Web application under the scan when it scans for changes.



Original link: http://www.gowhich.com/blog/539

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.