• tomcat 和 jboss的热部署(热发布)问题


    所谓的热部署(热发布)(下面称为“热部署”),就是说,在web工程发布之后,不可避免的,会遇到修改BUG的问题。现在的热部署就是为了解决这个问题,其功能就是说:在不停止web服务的同时,对jsp和Java类进行修改,修改后的效果同时还能够在页面上显示出来。节省了调试时间,提高了效率。不过,修改配置文件是个例外,如果对配置文件做修改,一定要重启web服务。
             常用的web服务器一般为tomcat和jboss,现一一做介绍。
             1.tomcat热部署
                      在tomcat中支持热部署有两种方式(在原理上来说,这两种方式是一致的,只是放的位置不同)
                     a)在catalina_base/conf/catalina/localhost/中依照manager.xml定义一个xml文件,比如我的项目称作sodoperation,我们就可以写一个sodoperation.xml,内容如下:
               <context path="/sodoperation"  docBase="d:/myportal/sodoperation/src/webapp"/>
                其中,path指的是你在tomcat中的项目名称,就像manager一样,docBase是指你的项目所在的web目录。一直到欢迎页面为止(也就是web-inf的前一个目录)。但是一般来说,这个目录中最好不要有中文,如果有的话,可以在文件开始加入
                <?xml version='1.0" encoding='utf-8' ?>来试一下,即整个文件变为:
                 <?xml version='1.0" encoding='utf-8' ?>
                <context path="/sodoperation"  docBase="d:/myportal/sodoperation/src/webapp"/>
               这样就可以了,如果用这种广告,同时使用myeclipse的部署的话,轻易不要remove,这样会使文件都会被删掉,不能持久。所以,建议使用第二种方法。
                  b)第二种方法和第一种方法在原理上是一致的,其区别就是位置的不同,这次在catalina_base/conf下的server.xml,在文件末加入:
          <context path="/sodoperation"  docBase="d:/myportal/sodoperation/src/webapp"/>
        解释和上面一样,这种方法在启动tomcat后,会在catalina_base/conf/catalina/localhost/中加入一个与第一种方法的文件。这样保证,只要对server.xml不做修改,你可以随便对新生成的文件删除,对热部署没有任何问题

    2.jboss热部署
         在jboss中做热部署也有两种方法,因为jobss集成了tomcat,也可以说这两种方法是在jobss上的一个修改。
         a)修改jboss-4.0.4RC1/server/default/deploy/jbossweb-tomcat55.sar/context.xml
          <Context cookies="true" crossContext="true" antiResourceLocking="true" antiJARLocking="true">
             <Manager pathname=""/>
             <InstanceListener>org.jboss.web.tomcat.security.RunAsListener</InstanceListener>
            </Context>
       加上红色的部分,重启jboss,再用myeclipse Redeploy project的时候就不需要重启,部署完了直接开浏览器预览啦

    在一个jboss中可以发布多个项目,如果修改一个项目后只想重启该项目,其它项目不重启,可以使用jboss的热部署。

    1、修改jboss的配置文件server/default/deploy/jboss-web.deployer/context.xml

          在Context元素中添加antiResourceLocking="true" 和  antiJARLocking="true" 属性,如下

     [html] view plain copy print?

    1. <Context cookies="true" crossContext="true" antiResourceLocking="true" antiJARLocking="true" >   
    2.    <Manager pathname=""/>       
    3.    <InstanceListener>org.jboss.web.tomcat.security.RunAsListener</InstanceListener>   
    4. </Context>  
    <Context cookies="true" crossContext="true" antiResourceLocking="true" antiJARLocking="true" > 
       <Manager pathname=""/> 	
       <InstanceListener>org.jboss.web.tomcat.security.RunAsListener</InstanceListener> 
    </Context>

    测试环境中,经常要更新代码,需要重新加载工程,以前的办法都是重启jboss,但是这个浪费太多的时间,有一个办法可以解决这个问题,就是jboss的热部署

    #vim /usr/local/jboss-4.2.3.GA/server/default/deploy/jboss-web.deployer/context.xml

    1. <Context cookies="true" crossContext="true" antiResourceLocking="true" antiJARLocking="true" >          
    2.     <Manager pathname=""/>          
    3.     <InstanceListener>org.jboss.web.tomcat.security.RunAsListener</InstanceListener>          
    4. </Context>  
    <Context cookies="true" crossContext="true" antiResourceLocking="true" antiJARLocking="true" >        
        <Manager pathname=""/>        
        <InstanceListener>org.jboss.web.tomcat.security.RunAsListener</InstanceListener>        
    </Context>

    加入红色部分,然后重启jboss,以后不需要重启jboss就可以加载工程

          

     

    2、重启Jboss

    3、修改项目下的web.xml(在web.xml中增加或者删除空行就可以),jboss就会只对该项目重新部署。

  • 相关阅读:
    阿里轻量应用服务器 Tomcat 注意的地方 Unsupported major.minor version 52.0(unable to load class
    微信小程序-进度条循环播放
    微信小程序-动画
    微信小程序-自定义分享
    微信小程序-引导页
    微信小程序-时间轴
    微信小程序-两次点击不同图片交换图片位置
    Kafka消费者——消费者客户端多线程实现
    Kakfa消费者——原理及分析
    Kafka基础——Kafka架构
  • 原文地址:https://www.cnblogs.com/firstdream/p/7154022.html
Copyright © 2020-2023  润新知