Installation
JRebel installs as a JVM plugin (-javaagent) and works by monitoring the timestamp of class files. When it is updated (e.g. when a developer saves a class from the IDE) JRebel will reload the changes to class code and structure while preserving all existing class instances. The loading is lazy and will happen upon usage of the class (method call on an instance, static call on the class, field lookup etc).
Quick Start
Some platforms and tools have their specific gotchas, so definitely take a look at the rest of the manual.
Step 0: Select your environment
窗体顶端
Java version: |
|
Operating system: |
|
Platform: |
Standalone applications BEA Weblogic 9.x+ GlassFish V2 Google App Engine 1.x IBM WebSphere 6.1+ JBoss 4+ Jetty 5+ Maven/Jetty Oracle Application Server 9.x Oracle Application Server 10.x Resin 3.0 Resin 3.1+ SAP NetWeaver 7.1 SpringSource dm Server 1.0 Tomcat 5+ Other |
窗体底端
Step 1: Configure the Platform
Tomcat
File: %TOMCAT_HOME%\bin\catalina.bat
Add the following line:
set JAVA_OPTS=-noverify -javaagent:jrebel.jar %JAVA_OPTS%
If you use the windows service or system tray startup use the following parameters instead:
-Xverify:none -javaagent:jrebel.jar
Step 2: Configure the Application
There are two ways to specify classes that will be monitored by JRebel for changes:
NB! Never place rebel.xml in system/server classpath as it will cause classloading errors!
The rest of this section applies only to rebel.xml configuration. If you’re using exploded or standalone development feel free to skip right ahead to the Configuring Tools section.
If you are using Maven to build your application, we’d suggest you to use the Maven JRebel plugin to generate rebel.xml for you. You can read about it in the Configuring Tools section.
Configuring JARs
JARs are usually not deployed on their own, but as a part of application (e.g. WEB-INF/lib in WARs or EJB modules in EARs). However often you still want to update their code on-the-fly. Let’s assume that we have a module my-business-module.jar deployed in WEB-INF/lib. You can propagate the changes from your workspace by adding the following rebel.xml to the root of the JAR file:
<?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/alderaan/rebel-2_0.xsd">
<classpath>
<dir name="c:\myWorkspace\myBusinessModule\target\classes"/>
<dir name="c:\myWorkspace\myBusinessModule\src\main\resources"/>
</classpath>
</application>
This will mount classes and resources in directories c:\myWorkspace\myBusinessModule\target\classes and c:\myWorkspace\myBusinessModule\src\main\resources before the classes and resources in the JAR file. Changes to those classes and resources will propagate to the application.
Configuring WARs
In the case of a web application you have web application resources, like JSPs, HTML files, graphic files and so on in addition to the classpath. To configure a web application deployed as a WAR file we create a rebel.xml file in the WEB-INF/classes directory:
<?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/alderaan/rebel-2_0.xsd">
<classpath>
<dir name="c:\myWorkspace\myWar\target\classes"/>
<dir name="c:\myWorkspace\myWar\src\main\resources"/>
</classpath>
<web>
<link target="/">
<dir name="c:\myWorkspace\myWar\src\main\webapp"/>
</link>
<link target="/jsps/">
<dir name="c:\myWorkspace\myWar\src\main\jsps"/>
</link>
</web>
</application>
This will mount classes and resources in directories c:\myWorkspace\myWar\target\classes and c:\myWorkspace\myWar\src\main\resources to the application classpath before the deployed classes and resources. This means that those classes and resources will override the ones in WEB-INF/classes and WEB-INF/lib/*.jar. Changes to those classes and resources will propagate to the application.
This will also map the web resources in the c:\myWorkspace\myWar\src\main\webapp directory to the root (”/”) of the web application context and the web resources in c:\myWorkspace\myWar\src\main\jsps directory under the /jsps/ URI of the web application context. You may map several directories to one context target if necessary.
Configuring EARs
To configure a EAR you need to create a separate rebel.xml file for each EAR module. Web modules should be configured same as individually deployed WARs, EJB modules should be configured same as JARs. If your container supports APP-INF/classes you may also add a rebel.xml to that folder and mount classes and resources that belong to the EAR as a whole.
Tips and Tricks
Read about those options and more in the configuration manual.
Step 3: Configuring Tools
To enable debugger to work with JRebel you should install this plugin.
You should configure the debugger to ignore synthetic methods. To do that open up debugger properties (File -> Settings -> Debugger). On the lower left corner of the debugger settings page make the necessary changes. Be sure to tick Skip synthetic methods checkbox and add the filters for com.zeroturnaround.* and org.zeroturnaround.*. You should also untick the checkbox Synthetic fields in the Show block of File -> Settings -> IDE settings -> Debugger -> Data Views
To stop IDEA from rebuilding the WAR file on every save right click on the web application, go to File -> Project Structure, click on the Web component of your web project (it’s a blue icon.), and then click on Java EE Build Settings. Uncheck both Create web facet war file, and Web Facet Exploded Directory.
Eclipse 3.x
You should also configure the debugger to ignore synthetic methods. To configure Eclipse go to Window -> Preferences and from there to Java -> Debug -> Step Filtering (or just search for “Step filtering”). Enable step filters and Filter synthetic methods. Make sure that Step through filters is also on. Now enable all the default filters and add com.zeroturnaround.* and org.zeroturnaround.*.
See also:
Netbeans 6.5
To enable debugger to work with JRebel you should install this plugin.
Maven 2.x
If you’re using Maven to build your application you can use the JRebel Maven plugin to automatically create a rebel.xml configuration file during the build.
To quickly configure the Maven plugin for war, jar and ejb modules add the following to your pom.xml:
<pluginRepository>
<id>zt-repo</id>
<name>Zero turnaround repo</name>
<url>dav:http://repos.zeroturnaround.com/maven2</url>
</pluginRepository>
...
<plugin>
<groupId>org.zeroturnaround</groupId>
<artifactId>jrebel-maven-plugin</artifactId>
<executions>
<execution>
<id>generate-rebel-xml</id>
<phase>process-resources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
For the rest of configuration options please visit the Maven plugin configuration manual.
ECLISPE WTP 集成 JAVAREBEL
JavaRebel 是一个 JVM 插件 (-javaagent) ,能够即时重载 java class 更改,因此不需要重新部署一个应用或者重启容器,节约开发者时间。
<!-- [if !supportLists]-->1、 <!-- [endif]-->下载j avarebel.jar 和 javarebel.lic 。注意
javarebel.jar 包不可改名,
javarebel.lic 放同目录
2 、 ECLIPSE 应用设好 TOMCAT 服务器后,进入【 Run > Run Configuration 】界面,在 VM 参数前加入 ”-noverify -javaagent:D:\tomcat5.5\bin\javarebel.jar ” ,如图:
<!-- [if gte vml 1]><v:shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"> <v:stroke joinstyle="miter" /> <v:formulas> <v:f eqn="if lineDrawn pixelLineWidth 0" /> <v:f eqn="sum @0 1 0" /> <v:f eqn="sum 0 0 @1" /> <v:f eqn="prod @2 1 2" /> <v:f eqn="prod @3 21600 pixelWidth" /> <v:f eqn="prod @3 21600 pixelHeight" /> <v:f eqn="sum @0 0 1" /> <v:f eqn="prod @6 1 2" /> <v:f eqn="prod @7 21600 pixelWidth" /> <v:f eqn="sum @8 21600 0" /> <v:f eqn="prod @7 21600 pixelHeight" /> <v:f eqn="sum @10 21600 0" /> </v:formulas> <v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect" /> <o:lock v:ext="edit" aspectratio="t" /> </v:shapetype><v:shape id="_x0000_i1025" type="#_x0000_t75" style="width:414.75pt; height:259.5pt" mce_style="width:414.75pt; height:259.5pt"> <v:imagedata src="file:///C:\DOCUME~1\FNDSOF~1\LOCALS~1\Temp\msohtml1\01\clip_image001.png" mce_src="file:///C:\DOCUME~1\FNDSOF~1\LOCALS~1\Temp\msohtml1\01\clip_image001.png" o:title="" /> </v:shape><![endif]--><!-- [if !vml]--><!-- [endif]-->
3 、双击 Server , Server 配置中选择自动发布,如图:
<!-- [if gte vml 1]><v:shape id="_x0000_i1026" type="#_x0000_t75" style="width:414.75pt;height:259.5pt" mce_style="width:414.75pt;height:259.5pt"> <v:imagedata src="file:///C:\DOCUME~1\FNDSOF~1\LOCALS~1\Temp\msohtml1\01\clip_image003.png" mce_src="file:///C:\DOCUME~1\FNDSOF~1\LOCALS~1\Temp\msohtml1\01\clip_image003.png" o:title="" /> </v:shape><![endif]--><!-- [if !vml]--><!-- [endif]-->
4 、 Server 模块中 Disable 掉 Auto Reload ,如图:
<!-- [if gte vml 1]><v:shape id="_x0000_i1027" type="#_x0000_t75" style="width:414.75pt;height:259.5pt" mce_style="width:414.75pt;height:259.5pt"> <v:imagedata src="file:///C:\DOCUME~1\FNDSOF~1\LOCALS~1\Temp\msohtml1\01\clip_image005.png" mce_src="file:///C:\DOCUME~1\FNDSOF~1\LOCALS~1\Temp\msohtml1\01\clip_image005.png" o:title="" /> </v:shape><![endif]--><!-- [if !vml]--><!-- [endif]-->
5 、这样就配置完成了。启动 Server ,在 Tomcat 启动日志前看见日志:
##########################################################
ZeroTurnaround JavaRebel 2.0-M1 (200812031605)
(c) Copyright Webmedia, Ltd, 2007, 2008. All rights reserved.
This product is licensed to Jacky Liu
##########################################################
6 、在修改类后,不需要重新发布,再次调用用, Console 输出:
JavaRebel: Reloading class 'com.nx.study.Test'.
7 、至此恭喜你,成功了!
8 、这个配置主要在集成测试方面有好的效率,并不能代替单元测试。