jrebel实现Java热更不用真是暴殄天物

基于eclipse IDE做Java开发,你不用jrebel就太可惜了!

为什么要用jrebel?

因为它能实现热更,就是你不需要重启程序,就能看到增加,修改,删除代码后的效果,减少了重启的次数,大大提升了开发效率!

我是做游戏开发的,下面是我的经验。

不用jrebel之前,我和前端调试功能是这样的,报错了,我就修改代码,然后重启,一般一次重启要花1分钟左右,重启后再调试发现还有问题于是我继续修改代码,然后继续重启,大量的重启导致大量的时间白白浪费!用了jrebel是这样的,发现错,我立马修改,这下就不用重启了,jrebel会帮我热更!然后让前端继续测试,有时发现bug,到验证bug修复就10几秒钟!这种效率的提升你可想而知!

不用jrebel之前,我们线上的游戏服出问题是这样的,发一个公告,停服维护30分钟,然后更新代码,然后再开服!用了jrebel之后是这样的,不用公告停30分钟了,直接把相应的class文件替换下,bug就解决了。玩家都感觉不到!就是这么方便!

下面分别是jrebel 在 eclipse 和 tomcat中的环境配置。

eclipse 配置 jrebel环境

1.从eclipse 超市安装  jrebel

2.下载破解文件 http://download.csdn.net/download/javaee1234/9719736
jrebel-5.6.3-crack 目录下的所有文件替换 D:\eclipse-jee-luna-SR1-win32-x86_64\eclipse\plugins\org.zeroturnaround.eclipse.embedder_5.6.3.SR1-201409161234\jrebel 下所有文件

3.将D:\eclipse-jee-luna-SR1-win32-x86_64\eclipse\plugins\org.zeroturnaround.eclipse.embedder_5.6.3.SR1-201409161234\jrebel 下的 jrebel.lic  复制到 C:\Users\Administrator\.jrebel 下


tomcat配置jrebel环境

1.将jrebel.jar 放到 tomcat 的lib目录下

2.catalina.sh 第一行加入:set JAVA_OPTS=-noverify -javaagent:..\lib\jrebel.jar


Tomcat7+eclipse+ JRebel 破解实现热部署

一 下载JRebel6.0.3的破解文件

首先从网上下载:jrebel_6.0.3-agent-crack.zip,并解压。下载地址:  http://pan.baidu.com/s/1eQnJmvw , 提取密码: c9gt

安装eclipse的JRebel6.0.3的插件

我使用的是eclipse4.4.2,安装插件跟安装其它插件无异。

安装插件:help--install new software--work with 处点add


图中location处输入插件更新地址,name处随便定义一个名字,如jrebel。     

如果自己提前下好插件包,可不用输入插件地址,直接点击 Archive,链接到下载好的插件包目录,可直接进行安装。

插件更新地址为:http://update.zeroturnaround.com/update-site-archive/update-site-6.0.3.RELEASE/ 。勾选全部->next

二 破解插件

我们把jrebel_6.0.3-agent-crack.zip解压,取出子目录lib下的  jrebel.jar 与 jrebel.lic 。把这两个文件复盖到eclipse安装目录下的pluginsorg.zeroturnaround.eclipse.embedder_6.0.3.RELEASE-201501271431文件夹下的所有的有jrebel.jar的子文件夹里,然后重启eclipse即可确。


三如何配置jrebel到项目中,分两种,一种是配置到java application项目,另外一种是配置到J2ee项目中

(1)配置到java application(c/s架构项目)

jrebel插件安装成功后,可看到help下面出现jrebel的菜单,如图


   1、为项目添加rebel.xml配置文件


添加后可在项目的src源目录下看到配置rebel.xml文件,图中的配置表示监听bin目录。此时rebel相当于一个代理。


2、点击run--run configuration,在Jrebel选项卡中勾选Enable Jrebel agent,表示启动Jrebel代理。




3、启动项目,看到如下打印表示配置成功。

2015-06-18 09:15:53 JRebel:  #############################################################
2015-06-18 09:15:53 JRebel:  
2015-06-18 09:15:53 JRebel:  JRebel Agent 6.0.3 (201501261446)
2015-06-18 09:15:53 JRebel:  (c) Copyright ZeroTurnaround AS, Estonia, Tartu.
2015-06-18 09:15:53 JRebel:  
2015-06-18 09:15:53 JRebel:  Over the last 1 days JRebel prevented
2015-06-18 09:15:53 JRebel:  at least 0 redeploys/restarts saving you about 0 hours.
2015-06-18 09:15:53 JRebel:  
2015-06-18 09:15:53 JRebel:  Licensed to anonymous-user
2015-06-18 09:15:53 JRebel:   with the following restrictions: 
2015-06-18 09:15:53 JRebel:   ####### Cracked by anonymous-user, For FUN! Unlimited! Enjoy! ######
2015-06-18 09:15:53 JRebel:  
2015-06-18 09:15:53 JRebel:  License type: perpetual
2015-06-18 09:15:53 JRebel:  
2015-06-18 09:15:53 JRebel:  
2015-06-18 09:15:53 JRebel:  #############################################################

修改java文件,点击保存,会自动加载。

输出台打印

2016-02-29 14:11:28 Test: Reloading class 'common.PrintOWin'.
2016-02-29 14:11:28 Test: Reloading class 'common.GameServer'.

(2)配置到J2ee项目(b/s架构项目),配置Server,这里用Tomcat7

如何在eclipse里添加server 这里就不讲了,自行百度

如果你已经用eclipse 创建了项目这里不用再创建,如果是新手上路刚刚配置好serve则新建Dynamic web project(或者maven webapp)项目(这里是shop,其它的java web项目也可以),然后 右键  Run As -> Run On Server  运行之后,停掉

打开项目工作空间Servers中的配置server.xml

<Context docBase="shop" path="/shop" reloadable="true" source="org.eclipse.jst.jee.server:shop"/>

reloadable="true"修改为reloadable="false"

server options 的配置如图左下角

四:配置JRebel

选择Help -> Jrebel Config Center 打开jrebel的配置中心

1:在Overview tab 中。右侧 Licensing 填入上部申请的License

2:左边Servers中,勾选上一步需要运行的服务器

3:左下侧Projects,勾选需要开发的项目

Advance  Tab基本默认即可


五:设置eclipse 菜单选择 Project » Build automatically 大功告成

启动tomcat,查看控制台输出

2015-06-18 09:15:53 JRebel:  #############################################################
2015-06-18 09:15:53 JRebel:  
2015-06-18 09:15:53 JRebel:  JRebel Agent 6.0.3 (201501261446)
2015-06-18 09:15:53 JRebel:  (c) Copyright ZeroTurnaround AS, Estonia, Tartu.
2015-06-18 09:15:53 JRebel:  
2015-06-18 09:15:53 JRebel:  Over the last 1 days JRebel prevented
2015-06-18 09:15:53 JRebel:  at least 0 redeploys/restarts saving you about 0 hours.
2015-06-18 09:15:53 JRebel:  
2015-06-18 09:15:53 JRebel:  Licensed to anonymous-user
2015-06-18 09:15:53 JRebel:   with the following restrictions: 
2015-06-18 09:15:53 JRebel:   ####### Cracked by anonymous-user, For FUN! Unlimited! Enjoy! ######
2015-06-18 09:15:53 JRebel:  
2015-06-18 09:15:53 JRebel:  License type: perpetual
2015-06-18 09:15:53 JRebel:  
2015-06-18 09:15:53 JRebel:  
2015-06-18 09:15:53 JRebel:  #############################################################

当看到有如下输出,就表示成功

2014-11-22 12:05:02 JRebel: Directory 'E:eclipse-jee-kepler-SR2-win32-x86_64srcshopbuildclasses' will be monitored for changes.
2014-11-22 12:05:02 JRebel: Directory 'E:eclipse-jee-kepler-SR2-win32-x86_64srcshopWebContent' will be monitored for changes.


接下来,就可以开始开发,热部署

服务器热部署的实现原理:http://blog.csdn.net/chenjie19891104/article/details/42807959 



eclipse和网上找到的破解包提取打包成无依赖,独立java程序可用的版本。独立java程序启动的时候增加如下的JVM参数即可 -server -Xmx512m -XX:MaxPermSize=128m -Djava.awt.headless=true -Drebel.spring_plugin=true -noverify -javaagent:D:\apps\jrebel6.4.3\jrebel.jar -Xbootclasspath/p:D:/apps/jrebel6.4.3/rebelboot.jar -Drebel.base=D:\apps\jrebel6.4.3\.jrebel -Drebel.disable_update=true D:\apps\jrebel6.4.3这个为解压后的路径,rebel.base参数指定了jrebel.lic所在的位置,因此无需拷贝到用户目录下。 控制台可以看到如下的输出表示jrebel配置成功。 2016-07-13 11:42:59 JRebel: WARN You are running JRebel using the -javaagent option on a system where -agentpath is supported. 2016-07-13 11:43:02 JRebel: 2016-07-13 11:43:02 JRebel: ############################################################# 2016-07-13 11:43:02 JRebel: 2016-07-13 11:43:02 JRebel: JRebel Agent 6.4.3 (201604210950) 2016-07-13 11:43:02 JRebel: (c) Copyright ZeroTurnaround AS, Estonia, Tartu. 2016-07-13 11:43:02 JRebel: 2016-07-13 11:43:02 JRebel: Over the last 1 days JRebel prevented 2016-07-13 11:43:02 JRebel: at least 1 redeploys/restarts saving you about 0 hours. 2016-07-13 11:43:02 JRebel: 2016-07-13 11:43:02 JRebel: Licensed to VIMACER (ZeroTurnaround) 2016-07-13 11:43:02 JRebel: with the following restrictions: 2016-07-13 11:43:02 JRebel: ### Hello World Cracked ### :) 2016-07-13 11:43:02 JRebel: 2016-07-13 11:43:02 JRebel: License type: enterprise 2016-07-13 11:43:02 JRebel: Valid from: July 14, 2014 2016-07-13 11:43:02 JRebel: Valid until: August 18, 2888 2016-07-13 11:43:02 JRebel: 2016-07-13 11:43:02 JRebel: 2016-07-13 11:43:02 JRebel: ############################################################# 2016-07-13 11:43:02 JRebel: 2016-07-13 11:43:04 JRebel: Monitoring Log4j configuration in 'xxxxx/log4j.properties'. 2016-07-13 11:43:06 JRebel: Monitoring properties in 'xxxxx\xxxx.properties'. 2016-07-13 11:43:32 JRebel: Reloading class 'xxxxx'. 2016-07-13 11:43:32 JRebel: Reconfiguring bean 'xxxxx' [xxxxx]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值