JRebel Eclipse热部署教程

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_34845394/article/details/85126203

JRebel+Eclipse热部署教程

在开发web项目时,常常修改很少的代码(例如配置文件或java代码)就需要重启服务器,来查看修改后的效果。如果项目比较大,重启一次服务器几十秒,这简直就是噩梦!

好在JRebel这个神器的存在,使得我们可以在修改代码后进行热部署,即不需要重启服务器,就可以查看修改后的效果!

下面记录一下JRebel的安装教程和使用方法。

Eclipse下JRebel的安装

  1. 打开Eclipse—->Help—->EclipseMarketplace
    20171124212037659
  2. 在搜索框输入jrebel,回车搜索
    20171124212055869
  3. 安装完成后,eclipse右上角会多出一个视图选项,同时Help菜单中也多出一个JRebel的菜单
    20171124212110264
    20171124212126219
  4. 点击Help—->JRebel—->Activation进入激活界面

    Jrebel 激活服务

  5. 激活完成后,JRebel已经默认配置好了。
    现在开始使用JRebel运行项目:
    • 右键点击你要使用JRebel的项目,会出现JRebelR选项,点击Add JRebel Nature,点击后src下会多出一个配置文件rebel.xml [选这个这个是为了可以监听你项目中class文件的变化,如果你修改了java代码,生成新的class后会被重新加载]
      20171124213043597
      20171124213902278
    • 可以运行项目了,右键项目,点击Run As—->Run Configuration,配置运行参数,然后Run
      20171124213608264
    • 看控制台,出现以下内容说明JRebel监控成功:
    2017-11-24 21:39:52 JRebel: Directory 'C:\Users\hasee\oxygen-workspace\crm01\build\classes' will be monitored for changes.
    2017-11-24 21:39:52 JRebel: Directory 'C:\Users\hasee\oxygen-workspace\crm01\WebContent' will be monitored for changes.
    2017-11-24 21:39:55 JRebel:  Starting logging to file: C:\Users\hasee\.jrebel\jrebel.log
    2017-11-24 21:39:55 JRebel:  
    2017-11-24 21:39:55 JRebel:  #############################################################
    2017-11-24 21:39:55 JRebel:  
    2017-11-24 21:39:55 JRebel:  JRebel Agent 7.1.2 (201711071615)
    2017-11-24 21:39:55 JRebel:  (c) Copyright ZeroTurnaround AS, Estonia, Tartu.
    2017-11-24 21:39:55 JRebel:  
    2017-11-24 21:39:55 JRebel:  Over the last 2 days JRebel prevented
    2017-11-24 21:39:55 JRebel:  at least 6 redeploys/restarts saving you about 0.2 hours.
    2017-11-24 21:39:55 JRebel:  
    2017-11-24 21:39:55 JRebel:  Licensed to fly fly (using myJRebel).
    2017-11-24 21:39:55 JRebel:  
    2017-11-24 21:39:55 JRebel:  
    2017-11-24 21:39:55 JRebel:  #############################################################
    2017-11-24 21:39:55 JRebel: 
    2017-11-24 21:39:55 JRebel: Monitoring Log4j configuration in 'file:/C:/Users/hasee/oxygen-workspace/crm01/build/classes/log4j.properties'.
    十一月 24, 2017 9:39:55 下午 org.apache.catalina.core.ApplicationContext log
    信息: Initializing Spring root WebApplicationContext
    21:39:55,852  INFO ContextLoader:304 - Root WebApplicationContext: initialization started
    21:39:55,979  INFO XmlWebApplicationContext:583 - Refreshing Root WebApplicationContext: startup date [Fri Nov 24 21:39:55 CST 2017]; root of context hierarchy
    2017-11-24 21:39:56 JRebel: Monitoring Spring bean definitions in 'C:\Users\hasee\oxygen-workspace\crm01\build\classes\applicationContext.xml'.
    21:39:56,197  INFO XmlBeanDefinitionReader:317 - Loading XML bean definitions from class path resource [applicationContext.xml]
    2017-11-24 21:39:56 JRebel: Monitoring properties in 'file:/C:/Users/hasee/oxygen-workspace/crm01/build/classes/druid.properties'. 
    
    • 这里说明class文件和webcontent中的文件会被监视,如果发生改变则会重新部署
      20171124214232554
    • 这里说明spring配置文件applicationContext.xml和德鲁伊连接池配置文件会被监听
      20171124214348166
      • 测试下,修改一段代码,给Action中加一个方法
      /***********************************
       * Test JRebel
       * @return
       ***********************************/
      @Action(value = "test", results = {
              @Result(name = "test", location = "customer_list", type = "redirectAction")
      })
      public String testJRebel() {
          System.out.println("Hello JRebel");
          return "test";
      }
      
      • 看到控制台输出:
      2017-11-24 21:45:43 JRebel: Reloading class 'com.fly.action.CustomerAction'.
      

补充

如果安装完成后项目无法启动,报错:

JRebel-JVMTI [FATAL] A fatal error occurred while proccessing the base java classes. The JVM has been shut down...

极有可能是以下原因:

  1. eclipse所在路径包含中文!
  2. 当前系统用户文件夹包含中文

JRebel 对Springboot的热部署支持

JRebel 已经能够支持Springboot项目的热部署了。
但是好像JRebel 只能支持到Spring4.x
Springboot的2.0.0版本使用了Spring5.0.4
使用JRebel 热部署2.0.0的项目时会报错

猜你喜欢

转载自blog.csdn.net/qq_34845394/article/details/85126203
今日推荐