Platinum Partner
netbeans

How to use JRebel with NetBeans IDE and Tomcat

The goal of this document is to explain how to use JRebel technology with NetBeans IDE 7.2.1 and a local installation of the Tomcat 7 servlet container. JRebel is able to work with remote servers too, but this will be the subject of another tutorial.

Install the JRebel plugin into NetBeans

The JRebel NetBeans plugin is available for NetBeans IDE 7.2.1.

To install the JRebel NetBeans plugin, you only have to:

  1. Start NetBeans IDE.
  2. Go to the Tools > Plugins menu and install the JRebel NetBeans Plugin;
  3. Once the JRebel plugin is installed, you’ll have to restart the IDE.

Activate your JRebel free license

Visit https://my.jrebel.com/register and create a free account. You can connect through your Facebook or Twitter account too, it’s free.

Once you are connected to your account, visit the Activate section of the website and copy the activation key to your clipboard (we’ll use it later):


Now, go to https://my.jrebel.com/plans to choose a free plan:
  • Scala: for Scala developments;
  • OSS: for Open Source software;
  • Social: for non-commercial projects;
Choose a plan and validate it.
Once you have added a plan to your account, switch to the IDE and go to the JRebel tab, into the Activation section, and paste the activation code you copied into your clipboard:


Your JRebel plugin will be automatically validated:


PS 1: If you don’t validate your JRebel plugin, you’ll still be able to configure it, but class reloading won’t work (you will see an error message during your application server’s startup). To make JRebel work, you need an activation code and an active plan.

PS 2: ZeroTurnaround (the creators of JRebel) have plans to simplify the licensing procedure. Please see: http://zeroturnaround.com/jrebel/jrebel-licensing-gets-simplified/ for details, even though I’m not sure whether this also affects free licensing.

Enable JRebel into Tomcat

First, locate your jrebel.jar file. This file is located into your netbeans_user_dir/jrebel/ folder. To determine your netbeans_user_dir folder, go to the Help menu, About dialog and check the value of the User directory field:


In our example, the jrebel.jar file path is C:\Java\__prefs__\nb\nb_userdir\jrebel\jrebel.jar. Your own path is probably different because I have customized my NetBeans user directory location.
Secondly, add the -javaagent:locationOfJrebelJarFile startup parameter to Tomcat. If you launch Tomcat from the IDE, use the Tomcat server properties diaog's Platform tab to add the startup parameter:


If you launch Tomcat as a Windows service, via a UNIX daemon, or via a simple BAT/SH script, add the parameter to the startup command.

Start Tomcat. You will see JRebel messages in the Tomcat logs, something like this:

[2012-12-09 00:35:53] #############################################################
[2012-12-09 00:35:53] 
[2012-12-09 00:35:53]  JRebel 5.1.0 (201210161346)
[2012-12-09 00:35:53]  (c) Copyright ZeroTurnaround OU, Estonia, Tartu.
[2012-12-09 00:35:53] 
[2012-12-09 00:35:53]  Over the last 4 days JRebel prevented 
[2012-12-09 00:35:53]  at least 38 redeploys/restarts saving you about 1.5 hours.
[2012-12-09 00:35:53] 
[2012-12-09 00:35:53]  This product is licensed to Jonathan Lermitage
[2012-12-09 00:35:53]  for non-commercial use only.
[2012-12-09 00:35:53] 
[2012-12-09 00:35:53]  License acquired through myJRebel server.
[2012-12-09 00:35:53] 
[2012-12-09 00:35:53]  You are subscribed for the plan "JRebel Social Plan",
[2012-12-09 00:35:53]  subscription is for lifetime.
[2012-12-09 00:35:53]  next license check with the server is required by 2013-01-08.
[2012-12-09 00:35:53] 
[2012-12-09 00:35:53]  The following plugins are disabled at the moment: 
[2012-12-09 00:35:53]  * Apache MyFaces plugin (set -Drebel.myfaces_plugin=true to enable)
[2012-12-09 00:35:53]  * Click plugin (set -Drebel.click_plugin=true to enable)
[2012-12-09 00:35:53]  * JRuby Plugin (set -Drebel.jruby_plugin=true to enable)
[2012-12-09 00:35:53]  * Jersey plugin (set -Drebel.jersey_plugin=true to enable)
[2012-12-09 00:35:53]  * Oracle ADF Core plugin (set -Drebel.adf_core_plugin=true to enable)
[2012-12-09 00:35:53]  * Oracle ADF Faces plugin (set -Drebel.adf_faces_plugin=true to enable)
[2012-12-09 00:35:53]  * RESTlet plugin (set -Drebel.restlet_plugin=true to enable)
[2012-12-09 00:35:53]  * Seam-Wicket plugin (set -Drebel.seam_wicket_plugin=true to enable)
[2012-12-09 00:35:53]  * Spring Data Plugin (set -Drebel.spring_data_plugin=true to enable)
[2012-12-09 00:35:53]  * WebObjects plugin (set -Drebel.webobjects_plugin=true to enable)
[2012-12-09 00:35:53] 
[2012-12-09 00:35:53] #############################################################

This message indicates JRebel is correctly registered into Tomcat and your license is active. Otherwise, you would see a message that indicates you license is not validated.

Enable JRebel in a Web Application project

Go to the Project Properties dialog of an application, open the Run tab, and uncheck the Deploy on save feature because it is not necessary since we’ll use JRebel to reload classes, instead:


In addition, in the Build > Compiling section, the Compile on Save feature has to be enabled.

Deploy your project  for the first time and visit a webpage, such as a Servlet that shows information. Return to the IDE and modify your Servlet code, save it, and refresh the webpage. The new content reflects your code changes.

Now, every time you have to remove, edit, or add logic (classes, configuration files, etc.) to your project, you only need to save your modifications. You don’t have to redeploy your project to see changes.

To finish, when JRebel is reloading stuff, you may see messages in the Tomcat logs, such as these:

[2012-12-09 00:50:20] JRebel: Reloading class 'fr.tikione.myfavs.WelcomeServlet'.
[2012-12-09 00:50:20] JRebel: Reloading class 'fr.tikione.myfavs.UserSession'.
[2012-12-09 00:50:20] JRebel: Reloading class 'fr.tikione.myfavs.WelcomeServlet$FORM_RESULT'.
[2012-12-09 00:50:20] JRebel: Reinitialized class 'fr.tikione.myfavs.WelcomeServlet$FORM_RESULT'.
[2012-12-09 00:50:20] JRebel: Reloading class 'fr.tikione.myfavs.WelcomeServlet$1'.
[2012-12-09 00:50:20] JRebel: Reinitialized class 'fr.tikione.myfavs.WelcomeServlet$1'.
[2012-12-09 00:50:20] JRebel: Reloading class 'fr.tikione.myfavs.dao.AccountController'.

Limitations

  • JRebel has some limitations. They are explained here: http://zeroturnaround.com/software/jrebel/features/. Supported technologies (servers, Java EE components, IDEs, etc.) are shown here: http://zeroturnaround.com/software/jrebel/what-we-support/.
  • If you use the hibernation feature of your operating system, you may have to restart your application server, otherwise the JRebel’s class reloading may not work (verified on Windows 7 with Tomcat 7.0.32, Oracle JDK 7u09, NetBeans IDE 7.2.1 and the JRebel 1.3 plugin based on the 5.1.0 JRebel framework).  
{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}