Common ways to deploy web projects in tomcat

 Common ways to deploy web projects in tomcat:

 

Example: project name --SpringMVC,

       Physical path --D:\STUDY\Workspaces\SpringMVC,

      Target URL access form -- http://localhost:8080/smvc/...;

 

Note: The following deployment methods are based on the default configuration of tomcat. If there are custom settings, you need to make corresponding adjustments.

 

Method 1 : Copy the project to the webapps directory; (the method used by myeclipse deployment)

Operation : Create a new folder named smvc under webapps, copy the "content of the web application" to the smvc folder, and start tomcat;

 

Description : The name of the folder is the root path when accessing, for example, the folder name is smvc2, and the URL is http://localhost:8080/smvc2/...;

 

          " Web application content"  refers to all files in the root directory of a standard web application . If the IDE is eclipse, the content defaults to WebContent

All files in the directory          , if it is myeclipse, the default is all files in the WebRoot directory, pay attention to the class file;

             

          The following deployment configurations are configured according to the default settings of eclipse.

 

 

Method 2 : Modify the server.xml file; (the method used by eclipse to create a new server deployment, the tomcat plug-in deployment can also be configured in this method )

Action : Add the following configuration to the host tag:

 

<Context path="/smvc" docBase="D:\STUDY\Workspaces\SpringMVC\WebContent" />

 

Note : The parameters configured here are required items, and parameters such as reloadable and workDir can be added as needed, the same below;

 

           It is said that doBase can match relative paths according to webapps, but I haven't tried it.

 

           

Method 3 : Add an xml configuration file in the conf\Catalina\localhost directory; ( this method can be configured for tomcat plugin deployment )
 

Operation : Create a new file named smvc.xml , and the content of the file is configured as follows:

 

<Context docBase="D:\STUDY\Workspaces\SpringMVC\WebContent" />

 

Note : The tomcat in the Catalina\localhost directory is not available by default when it is downloaded. It will be created automatically at the first startup, or it can be created manually;

 

          配置中去掉path属性,因为配了也没用,访问项目时的根路径只取决于XML文件的名称

 

          如果没有WebContent目录,内容直接放在项目根目录下,那这个xml文件按理就需要命名为“.xml”,要是

         人为这么命名,操作系统是不允许的,但是用tomcat插件部署确可以做到,比较神奇。

 

         推荐使用第三种方式,因为不需要修改tomcat默认配置,并且如果想取消部署,直接删除xml配置文件即可;

 

--------------------------------------------------------------------------------------------------------------------------------------------

 

     这三种方式个人感觉是比较常用,但 tomcat 5.5之后独立出了context.xml,并且官方不再提倡修改server.xml,即本文中的方式二,曾尝试在context.xml中只做部署配置,但没成功,网上查了一下,很多提到配置context.xml的都是配置数据源之类的,官网也没有找到如何利用context.xml文件部署项目,所以一直没搞清楚利用context.xml到底能不能、又如何部署web项目,关注一下这个问题。

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326710797&siteId=291194637