JRebel Resource Center

Eclipse & JRebel Tutorial

***

Before you start – Prerequisites

JRebel for Eclipse requires Eclipse 3.3 (Europa) or later. Some optional features require additional Eclipse plug-ins, such as WTP (Web Tools Platform). This guide and most of the screenshots were made with Eclipse Helios on Windows 7. The process might vary a little bit for other Eclipse versions and operating systems.

***

Though JRebel does not depend on any IDE or development tools in particular (besides a compiler), it’s nice to have tight integration with your IDE. Enter JRebel for Eclipse. Remember: as long as you overwrite your old class files with new ones, JRebel will reload your changes and cut down on time spent redeploying.

JRebel for Eclipse already includes JRebel itself, helps you generate the JRebel configuration automatically, enables JRebel for applications and servers with a single click, and improves the debugging support in Eclipse. This article will help you to set up the plugin and take advantage of the features.

Step 1: Installing JRebel for Eclipse

Eclipse 3.6 Helios (and newer) – Install via the Eclipse Marketplace Client

To install JRebel for Eclipse, open the Eclipse Marketplace Client (Help -> Eclipse Marketplace…). If you open it for the first time, you have to select a solution catalog. Select “Eclipse Marketplace” and search for “JRebel”. Then just click the “Install” button next to it.

Eclipse 3.3, 3.4 & 3.5 – Installing via the Update Manager

Installing via the Update Manager is similar to installing via the Eclipse Marketplace. Go to Help -> Install New Software… and paste in the URL for our JRebel Update Site: http://zeroturnaround.com/update-site/

To make the installation process go faster, you might want to uncheck “Contact all update sites…” if you already have all the prerequisites. For example, the “Eclipse IDE for Java EE Developers” package contains everything you need, including WTP.

Step 2: Selecting Features and Finishing the Install Process

Select the features you want to install. JRebel plugin is required and should be installed by everyone (even your grandmother). Here’s what is included:

  • The plugin contains a complete installation of JRebel, the latest stable version, so you won’t have to download it separately — you’ll only need to get a license after installation and you are set.
  • The plugin also includes Eclipse Debugger Integration helps the IDE debugger to recognize new code and be able to set breakpoints.

JRebel for Java EE plugin is optional but most likely you want to install that one as well. The plugin is recommended if you want to use WTP (Web Tools Platform) with JRebel-enabled projects.

JRebel m2eclipse is available if installing from update site. This plugin enables generating rebel.xml configuration with jrebel-maven-plugin in m2eclipse builds.

Once you’ve selected the features you want, just proceed through the installation wizards normally. You will be asked to accept the license agreements, which are the Apache License and JRebel License Agreement. After the installation has completed, makes sure to restart Eclipse.

Step 3: Configuring JRebel and Adding Your License Key

After restarting the IDE, if you do now have JRebel license installed yet, the plugin will notify you about this sad fact and ask for registration. Click on the link in the red pop-up and proceed with the license setup.

By clicking on the link the plugin will take you to the JRebel activation window where you will have to select which license you would like to apply for:

By selecting the evaluation license option you will be directed to the JRebel Registration Form. Once the form is submitted, you will be provided the license key which you have to paste into the text area in activation window of the eclipse plugin. The license code will be verified and saved as jrebel.lic file in {user.home}./jrebel directory.

Step 4: Using JRebel in Eclipse

Step 4.1: Enable “Build Automatically” mode

First go to Project » Build automatically and make sure it is checked.

Step 4.2: Enable JRebel nature for the project

In order to do its magic, JRebel needs to know where your classes and resources are. We’ll use a rebel.xml configuration file to tell it. This is mandatory when you deploy your app as a WAR/EAR. You’ll need to have one rebel.xml file per module. This includes both web and EJB modules. The rebel.xml configuration file should be placed in your WEB-INF/classes directory in the case of a web module and in the jar root in the case of an ejb module. The rebel.xml configuration file is generated automatically when you enable JRebel Nature for the project.

If you use Maven you can use the JRebel Maven plugin that will generate the rebel.xml in accordance with the module pom.xml as described in the Maven Plugin configuration manual.

In 99% of cases, you probably use one module per project. In these cases, automatically generated rebel.xml should be OK. If your project is one of the exceptions, edit the file manually as described in the JRebel Installation Manual.

If you’d like to use one rebel.xml for your whole team, start with the generated rebel.xml, then replace the absolute paths to your workspace with a system property. 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 you to use a single configuration for everyone and then customize it when starting the server.

If everyone on your team uses Eclipse and a similar workspace layout, you can even skip using a custom property as every application or server launched with JRebel for Eclipse will have the property rebel.workspace.path set to the Eclipse workspace location and you can use it as “${rebel.workspace.path}” in rebel.xml.

Step 4.3: Launch application with JRebel

Whenever you run a program you can enable JRebel for that run configuration. This means that once enabled then the -javaagent:your_location/jrebel.jar will be added automatically to the startup flags. Checking the debug checkbox will also generate a JRebel.log in your Eclipse workspace metadata folder or in the location of the jrebel.jar file.

To enable, disable JRebel just navigate to the JRebel tab for your run configuration and use the checkboxes.

Step 4.4: Configuring WTP

Automatic publishing should be disabled in the server configuration. Double click on your server name and a configuration page opens. Under the Publish section you should have the Never publish automatically option selected as shown in the following screenshot.

Don’t forget to generate rebel.xml for webapps, otherwise JRebel may not be able to pick up changes to static resources.

Step 4.5: Success!

To check that the installation was successful, access a page that uses a class, change that class in the IDE, press Save, access the page again and look for the following message in the console:

2009-07-15_150006

Now that you’re up and running, it’s time to enjoy coding without the need to redeploy. If you have any specific questions JRebel, the Forum is the best place to ask, so that other people get to hear the answer as well. Otherwise, you can contact us at support@zeroturnaround.com.

If you like what you see, please give us a quick mention on your blog or twitter (you can even follow us here).

Have a great day!