本文以javarebel-2.0 free版本为例,包括如何配置在使用Eclipse插件开发tomcat应用时,实现即时重载java class更改。
1. 首先下载JavaRebel, 官方下载(Free版本) , 下载后解压到本地目录,例如 D:/javarebel.jar
2. 因为JavaRebel在不同的jdk版本,配置也不同,本例以JDK5+以上版本为例
在Eclipse的tomcat插件中,配置 JavaReble, 如图
在Jvm配置中加入下面的设置
-noverify
-javaagent:D:/javarebel.jar
-Drebel.dirs=D:\project\WEB-INF\classes
-Drebel.spring_plugin=true
说明:
-Drebel.dirs 指定要监控的 编译后的java 文件目录
-Drebel.spring_plugin 表示对Spring的支持,默认是false
配置完上面后,还需要关闭tomcat的应用程序的reloadable设置
<Context path="/hello" reloadable="false" docBase="D:\project" />
接下来,可以启动Tomcat服务了,如果配置正确,启动服务后,会有以下提示
#############################################################
ZeroTurnaround JavaRebel 2.0 (200903241906)
(c) Copyright Webmedia, Ltd, 2007-2009. All rights reserved.
You are running JavaRebel evaluation license.
You have 30 days until the license expires.
You will see this notification until you obtain a
full license for your installation.
Visit www.javarebel.com for instructions on obtaining
a full license. If you wish to continue your evaluation
please e-mail to support@zeroturnaround.com.
If you think you should not see this message contact
support@zeroturnaround.com or check that you have your
license file in the same directory as the JAR file.
#############################################################
JavaRebel: Directory 'D:\develop\WEB-INF\classes' will be monitored for class changes.
=============================== [JavaRebel Spring Framework Plugin] ===============================
Plugins are contributed by third party and can cause compatibility problems.
If you have any troubles set -Drebel.spring_plugin=false to disable it.
------------------------------------------------------------------------------------------
Description: Supports adding new beans and adding new bean dependencies using
annotations or XML. Singletons will be reconfigured after the change. It also
supports adding or changing Spring MVC controllers or handlers.
=============================== [/JavaRebel Spring Framework Plugin] ==============================
如果出上以上提示,则表示JavaRebel已经配置成功。
接下来大家可以在Eclipse中修改代码,进行编译进行测试。
如果Eclipse提示, 则直接关接不理它即可,你发现你修改后的 class文件已经被jvm加载了