Several ways to deploy web applications in tomcat

The main ways to deploy web applications in tomcat are as follows: (1) use tomcat's automatic deployment (2) use console deployment (3) add custom web deployment files (4) modify server.xml file to deploy web applications The first deployment method is the simplest and most commonly used method. It only needs to copy a web application to Tomcat's webapps. However, if there are multiple applications deployed in a tomcat, and the applications need to call each other's interfaces during the startup process, there will be a problem of which application starts first. How to make an application start first, and then start other applications? The third deployment method needs to create a new Catalina directory in the conf directory, then create a new localhost directory in the Catalina directory, and finally create a new xml file with an arbitrary name . Configuration file for the web application. For example: create a new aa.xml file, then fill in the path as aa








<Context path="/aa" reloadable="false" docBase="F:/xxx/xxx/xxx" workDir="" privileged="false" sessionCookieName=""></Context>

Parameter description:
  (1) The workDir in the above code represents the working directory where the web application is deployed after deployment (all servlets compiled from JSP in the web application can be found in it). If Eclipse is used as the IDE, it can be set manually. In the work directory of WebApp.
If the workdir is not specified in the custom web deployment file XXX.xml, the web application will be deployed by default in a new folder named XXX under the path of %Tomcat_Home%\work\Catalina\localhost\. ( All the Servlets compiled from JSP in the web application can be found in it )

(2) Context path is the virtual path name of the specified web application. docBase specifies the source path of the web application to be deployed .
   Debug is to set the debug level, 0 means to provide the least information, 9 means to provide the most information , only when
   privileged is set to true, Tomcat's web application is allowed to use the Servlet
   reloadable in the container. If it is true, tomcat will automatically detect the application Changes in the /WEB-INF/lib and /WEB-INF/classes directories of the program will automatically load new applications, and the application can be changed without restarting tomcat to achieve hot deployment.
   AntiResourceLocking and antiJARLocking hot deployment are parameters that need to be configured. The default is false to avoid updating a webapp. Sometimes Tomcat cannot completely delete the old webapp, usually leaving a jar package under WEB-INF/lib, which must be closed. Tomcat can only be deleted, which causes automatic deployment to fail. When set to true, Tomcat will copy the corresponding source files and jar files to a temporary directory when running the corresponding webapp. The
fourth deployment method opens the %Tomcat_Home%\conf\server.xml file and adds the following elements to it:
<Context path="/xxx" reloadable="false" docBase="F:/xxx/xxx/xxx" workDir="" privileged="false" sessionCookieName=""></Context>

The difference between the third deployment method and the fourth deployment method: server.xml and &{TOMCAT_HOME}\conf\Catalina\localhost.
   1. If the server.xml file is not configured
   
<Context path="/aa" reloadable="true" docBase="F:/xxx/xxx/xxx/" > </Context>
Instead, configure an aa.xml file in the ${TOMCAT_HOME}\conf\Catalina\localhost directory with the contents of
   
<Context path="/aa" reloadable="true" docBase="F:/xxx/xxx/xxx/" > </Context>
[/color] The tomcat loads the a.xml file directly.
    2. If configured in the server.xml file, pay attention to path="/a"
   
<Context path="/a" reloadable="true" docBase="F:/xxx/xxx/xxx/" > </Context>
Configure an a.xml under localhost. Note that if the name is a.xm, a under localhost will not be loaded. Because the path="/a" in server.xml has the same name as a.xml in the localhost directory
, it is only loaded once.
   3. If configured in the server.xml file, pay attention to path="/a"
    
<Context path="/a" reloadable="true" docBase="F:/xxx/xxx/xxx/" > </Context>
Configure an abc.xml under localhost, note that the name is abc.xml, then both configurations will be loaded.
Summary:
Some of the projects encountered so far have used the first method to deploy, and some have used the third method to deploy. The first method deploys the same tomcat if multiple web projects are deployed, and the project needs to be started during the startup process. When calling the interface, there will be a problem of which application starts first, otherwise the interface call will fail. How to control the startup order of the web application, which is another question?

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326071468&siteId=291194637