2017年最新JRebel+Eclipse热部署教程

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

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

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


Eclipse下JRebel的安装和使用

0x0 下载安装Jrebel(模仿大神们的装逼排序方法)

  1. 打开Eclipse—->Help—->EclipseMarketplace; 
    这里写图片描述
  2. 在搜索框输入jrebel,回车搜索; 
    这里写图片描述
  3. 安装完成后,eclipse右上角会多出一个视图选项,同时Help菜单中也多出一个JRebel的菜单; 
    这里写图片描述
    这里写图片描述
  4. 点击Help—->JRebel—->Activation进入激活界面; 
    这里写图片描述
  5. 这里要输入激活码,然后点击激活按钮,途中按钮和你们的不同是因为我的已经激活。

0x1 激活Jrebel

以下介绍如何获取激活码(免费的哦):

  1. 进入jrebel官网:https://my.jrebel.com/

  2. 注册账号密码,并登陆;

  3. 登陆后,出现下图,点击subscribe订阅 
    这里写图片描述

  4. 用twitter或者facebook进行订阅(需要翻墙) 
    这里写图片描述
  5. 订阅成功后,点击install and active,就会出现喜闻乐见的激活码: 
    这里写图片描述

  6. 在eclipse中输入激活码激活,点即右上角的JRebel,切换到Jrebel视图,可以看到下图: 
    这里写图片描述


0x2 使用Jrebel

激活完成后,JRebel已经默认配置好了。 
现在开始使用JRebel运行项目:

非Maven项目 
1. 右键点击你要使用JRebel的项目,会出现JRebelR选项,点击Add JRebel Nature,点击后src下会多出一个配置文件rebel。xml 
选这个这个是为了可以监听你项目中class文件的变化,如果你修改了java代码,生成新的class后会被重新加载) 
这里写图片描述 
多出来的配置文件rebel.xml 
2. 可以运行项目了,右键项目,点击Run As—->Run Configuration,配置运行参数,然后Run 
这里写图片描述
3. 看控制台,出现以下内容说明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'. 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

这里写图片描述
这里说明class文件和webcontent中的文件会被监视,如果发生改变则会重新部署

这里写图片描述
这里说明spring配置文件applicationContext.xml和德鲁伊连接池配置文件会被监听

  1. 测试下,修改一段代码,给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";
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

看到控制台输出:

2017-11-24 21:45:43 JRebel: Reloading class 'com.fly.action.CustomerAction'.
  • 1

大功告成了

补充

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

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

极有可能是以下原因: 
1. eclipse所在路径包含中文! 
2. 当前系统用户文件夹包含中文

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值