JRebel installs

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

  • On Java 5 add -noverify -javaagent:/path/to/jrebel.jar to the JVM command line.
  • On Java 1.4 you need to run java -jar jrebel.jar and then add -Xbootclasspath/p:/path/to/jrebel-bootstrap.jar;/path/to/jrebel.jar to the JVM command line.
  • If you use exploded development or a standalone application then set IDE to compile to WEB-INF/classes or system classpath and changes will be picked up immediately on save.
  • If you deploy as a WAR or an EAR then you need to create a rebel.xml configuration file as described further.

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:

Java 5 or later | Java 1.4

Operating system:

Windows | Unix-like (Linux, Mac OS X, etc)

Platform:

Standalone applicationsBEA Weblogic 9.x+GlassFish V2Google App Engine 1.xIBM WebSphere 6.1+JBoss 4+Jetty 5+Maven/JettyOracle Application Server 9.xOracle Application Server 10.xResin 3.0Resin 3.1+SAP NetWeaver 7.1SpringSource dm Server 1.0Tomcat 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:

  1. All .class files in application classpath will be monitored by default (including system classpath, WEB-INF/classes, EJB module root, but exluding packaged JARs, WARs and EARs). If you use exploded or standalone development it is suggested to set the IDE compile output to application classpath and changes will be picked up on save.
  2. You can put a rebel.xml file in the application or module classpath to mount external folders to the application classpath. There should be one rebel.xml file per application or module. It can be placed in:
    • WEB-INF/classes
    • APP-INF/classes
    • EJB Module JAR root
    • Library JAR root

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

  • Putting absolute paths in the rebel.xml might be a bad idea as you’d like to share it with other team members. Luckily JRebel will expand expressions like “${myProject.root}” in rebel.xml to a system property that you can pass to the application container as -DmyProject.root=c:/myWorkspace/myProject. This allows to use a single configuration for everyone and then customize it when starting the server.
  • You are not limited to mounting directories to classpath. You can also mount JARs with <jar>.
  • If you need to mount a bunch of directories or JARs at once you can use <dirset> or <jarset> that accepts Ant-style patterns to specify the specific directories.
  • You can use Ant FileSet-style include and exclude directives in <dir> and <jar> entries.

Read about those options and more in the configuration manual.

Step 3: Configuring Tools

IntelliJ IDEA 

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
放同目录

 

2ECLIPSE 应用设好 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 、双击 ServerServer 配置中选择自动发布,如图:

<!-- [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]-->

 

 

4Server 模块中 DisableAuto 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 、这个配置主要在集成测试方面有好的效率,并不能代替单元测试。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值