美文网首页
war与war exploded区别

war与war exploded区别

作者: 50e383299c68 | 来源:发表于2018-01-15 20:19 被阅读0次

    在使用IDEA开发项目的时候,部署Tomcat的时候会出现这样的情况:
    是选择war模式,还是war exploded模式。
    这两个模式有什么区别呢?

    war模式:将WEB工程以包的形式上传到指定的服务器(tomcat)
    war exploded模式:将WEB工程以当前文件夹的位置关系上传到服务器(tomcat)。

    1. war模式:称之为发布模式,先打成war包,再发布;
    2. war exploded模式:是直接把文件夹、jsp页面 、classes等等移到Tomcat 部署文件夹里面,进行加载部署。因此这种方式支持热部署,一般在开发的时候也是用这种方式。

    
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.RestController;
    import javax.annotation.PostConstruct;
    @RestController
    @RequestMapping("/")
    public class HelloController {
        @PostConstruct
        private void init() {
            System.out.println("初始化:HelloController");
        }
    
        @RequestMapping(method = RequestMethod.GET)
        public String printWelcome() {
            // 获取web项目的根路径
            String path = this.getClass().getResource("/").getPath();
            return path;
        }
    } 
    

    通过上面的代码测试两个部署方式,web项目的实际根目录。
    本地代码的测试结果是:

    1. war模式输出:/Users/jessie/local/apache-tomcat-7.0.68/webapps/demod/WEB-INF/classes/
    2. war exploded模式输出:/Users/jessie/project/demo/target/demod/WEB-INF/classes/

    由输出结果可以看出:

    1. war模式部署在指定的tomcat里面的webapps下。
    2. war exploded模式在当前的项目的target里面。

    相关文章

      网友评论

          本文标题:war与war exploded区别

          本文链接:https://www.haomeiwen.com/subject/lygdoxtx.html