war包发布方法

少于 1 分钟阅读

Contact me

或者用邮件交流 jacky.wucheng@foxmail.com

tomcat基础知识

  • tomcat重要概念: server, connector, container
    • Server
    • Connector
    • Container
      • Engine (handles all requests for a Service)
      • Host (handles all requests for a particular virtual host)
      • Context (handles all requests for a specific web application)

tomcat webapps/ROOT目录结构

 
    
    #
    ROOT git:(master) ✗ tree /Users/jacky/myArticles/java_ecosystem/tomcat/tomcat/apache-tomcat-8.0.24/webapps/ROOT
    /Users/jacky/myArticles/java_ecosystem/tomcat/tomcat/apache-tomcat-8.0.24/webapps/ROOT
    ├── RELEASE-NOTES.txt
    ├── WEB-INF
    │   └── web.xml
    ├── build.xml
    ├── favicon.ico
    ├── index.jsp
    ├── ... ...

war包结构(zip压缩格式):

 

    #
    Archive:  servletDemo.war
      inflating: META-INF/MANIFEST.MF
       creating: WEB-INF/
       creating: WEB-INF/classes/
       creating: WEB-INF/classes/com/
       creating: WEB-INF/classes/com/jacky/
       creating: WEB-INF/classes/com/jacky/www/
      inflating: WEB-INF/classes/com/jacky/www/Demo.class
       creating: WEB-INF/lib/
      inflating: WEB-INF/web.xml
      inflating: hello.jsp

war包里的结构跟webapps/ROOT下的结构一摸一样

发布方法1

打包war包(例如demo.war), 然后上传到tomcat/webapps目录下, tomcat会解压到当前目录, demo目录. 访问方法

 
    
    /demo/xxx

该方法的限制是, 会在根目录下加了一层demo子目录.

发布方法2

在conf/server.xml里添加

 

    <Context docBase="/path/to/demo.war" path="/" reloadable="true"/>

访问方法是

 

    http://ip:port/demo/
    

发布方法3

发布到根目录, 以根目录方式访问

  1. 解压war包到webapps以外的目录, 如 /workspace/demo
  2. 删除$TOMCAT_HOME/webapps/ROOT目录下的所有文件
  3. 在$TOMCAT_HOME/conf/Catalina/localhost目录下,新建一个ROOT.xml文件,写入
 

    <Context path="/" docBase="/workspace/demo" debug="0"   privileged="true" reloadable="true"/>

参考