idea Tomcat 部署 war和war exploded的区别 idea Tomcat 部署 war和war exploded的区别

idea Tomcat 部署 war和war exploded的区别

<div class="article-info-box">
    <div class="article-bar-top d-flex">
                    <span class="c-gray">置顶</span>
                                            <span class="time">2017年06月16日 10:52:15</span>
        <div class="float-right">
            <span class="read-count">阅读数:7623</span>
                                        </div>
    </div>
</div>
<article>
    <div id="article_content" class="article_content clearfix csdn-tracking-statistics" data-pid="blog" data-mod="popu_307" data-dsm="post">
                <link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/template/css/htmledit_views-0a60691e80.css">
        <div class="htmledit_views">

war和war exploded的区别

在使用IDEA开发项目的时候,部署Tomcat的时候通常会出现下边的情况:

这里写图片描述

是选择war还是war exploded 这里首先看一下他们两个的区别:

war模式:将WEB工程以包的形式上传到服务器 ;
war exploded模式:将WEB工程以当前文件夹的位置关系上传到服务器;
  • 1
  • 2
  • 1
  • 2

(1)war模式这种可以称之为是发布模式,看名字也知道,这是先打成war包,再发布;

(2)war exploded模式是直接把文件夹、jsp页面 、classes等等移到Tomcat 部署文件夹里面,进行加载部署。因此这种方式支持热部署,一般在开发的时候也是用这种方式。

(3)在平时开发的时候,使用热部署的话,应该对Tomcat进行相应的设置,这样的话修改的jsp界面什么的东西才可以及时的显示出来。

这里写图片描述

修改箭头指向的位置,这样的话就可以实现热部署。

使用war模式开发的时候遇到的坑

一、项目代码的位置如下:

这里写图片描述

上述项目为SSM项目。

扫描二维码关注公众号,回复: 1545901 查看本文章

二、部署使用的Tomcat位置:

这里写图片描述

三、用于获取上下文环境绝对路径的代码:

String contextPath = request.getSession().getServletContext().getRealPath("/");
  • 1
  • 1

四、两种方式的实验过程和结果:

(1)在使用war模式开发的时候,通过下边这段代码获取项目的相对路径:

String contextPath = request.getSession().getServletContext().getRealPath("/");
  • 1
  • 1

war模式始终是获取到的路径如下:

这里写图片描述

其中C:\Software\apache-tomcat-8.0.32 是我Tomcat的所在位置。

可以看出通过war模式是最终打包部署到Tomcat的位置。

(2)然后再看war exploded模式,同样进行设置,运行同一段代码,运行结果如下:

这里写图片描述

可以看出最终得到的是我这个项目的位置,其实就是这个项目target的位置。

五、总结

根据上述(1)(2)的实验结果可以看到这两种方式得部署方式是不一样的,因此在获取项目的相对路径的时候得到的结果是不一样的。

        </div>
            </div>
        </article>

    <div class="article-bar-bottom">
                            <div class="tags-box">
        <span class="label">个人分类:</span>
                    <a class="tag-link" href="https://blog.csdn.net/linjpg/article/category/6921877" target="_blank">maven                      </a>
    </div>
                </div>

<!-- !empty($pre_next_article[0]) -->
    </div>

猜你喜欢

转载自blog.csdn.net/fle123/article/details/80602527