应用环境:
JDK: 1.6.0_26 + Tomcat6 + eclipse3.7.2 + JRebel5.0.1
系统架构
struts2 + spring3 + ibaits2.3
配置步骤:
1、下载JRebel工具包(本文附件),把此包放置至Tomcat lib目录下(应该可放置其他目录,大家可自已试下,后续会配置指向此路径)
2、打开Tomcat配置页面,如下图:
3、配置VM arguments参数,在已有参数后增加如下代码
-javaagent:E:\work\64\apache-tomcat-6.0.35\lib\jrebel.jar -noverify
如下图:
4、修改需热部署项目原有的部署参数,如下图:
5、在需热部署的项目src目录下添加名称为rebel.xml的配置文件(可在附件中下载),内容如下:
<?xml version="1.0" encoding="UTF-8"?> <application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://www.zeroturnaround.com/alderaan/rebel-2_0.xsd"> <classpath> //项目源代码class路径,有些为项目名\bin <dir name="F:\workspace\rom\build\classes"> </dir> </classpath> <web> <link target="/"> <dir name="F:\workspace\rom\WebContent"> </dir> </link> </web> </application>
至此配置完成,启动项目,控制台打印如下信息未出现异常,即说明配置成功:
[2012-09-17 20:57:25] [2012-09-17 20:57:25] ############################################################# [2012-09-17 20:57:25] [2012-09-17 20:57:25] JRebel 5.0.0 (201206080930) [2012-09-17 20:57:25] (c) Copyright ZeroTurnaround OU, Estonia, Tartu. [2012-09-17 20:57:25] [2012-09-17 20:57:25] Over the last 1 days JRebel prevented [2012-09-17 20:57:25] at least 9 redeploys/restarts saving you about 0.4 hours. [2012-09-17 20:57:25] [2012-09-17 20:57:25] This product is licensed to Unlimited [2012-09-17 20:57:25] For FUN! Unlimited! Enjoy! [2012-09-17 20:57:25] [2012-09-17 20:57:25] The following plugins are disabled at the moment: [2012-09-17 20:57:25] * Apache MyFaces plugin (set -Drebel.myfaces_plugin=true to enable) [2012-09-17 20:57:25] * Click plugin (set -Drebel.click_plugin=true to enable) [2012-09-17 20:57:25] * JRuby Plugin (set -Drebel.jruby_plugin=true to enable) [2012-09-17 20:57:25] * Jersey plugin (set -Drebel.jersey_plugin=true to enable) [2012-09-17 20:57:25] * Oracle ADF Core plugin (set -Drebel.adf_core_plugin=true to enable) [2012-09-17 20:57:25] * Oracle ADF Faces plugin (set -Drebel.adf_faces_plugin=true to enable) [2012-09-17 20:57:25] * Seam-Wicket plugin (set -Drebel.seam_wicket_plugin=true to enable) [2012-09-17 20:57:25] * WebObjects plugin (set -Drebel.webobjects_plugin=true to enable) [2012-09-17 20:57:25] [2012-09-17 20:57:25] ############################################################# [2012-09-17 20:57:25] [2012-09-17 20:57:25] [2012-09-17 20:57:25] JRebel: A newer version '5.0.1' is available for download [2012-09-17 20:57:25] JRebel: from http://www.zeroturnaround.com/jrebel/upgrade/ [2012-09-17 20:57:25]
当修改代码保存后,控制台会打印如下信息,即说明配置已生效,不需再等待重部署就可以看到修改后的效果,是不是感觉很爽,^-^
[2012-09-17 21:04:57] JRebel: Reloading class 'com.alili.rom.action.system.admin.UserAction'.
注: 经实际项目中应用,只有当修改Spring配置文件时,才需重新部署项目,而修改struts、ibatis等配置文件会自动热部署。