Hi! My name is Jonathan Lermitage and I am a French programmer. I work with the Java EE, SOA and BPM ecosystems and the NetBeans IDE since 5 years. Jonathan has posted 4 posts at DZone. You can read more from them at their website. View Full User Profile

How to use JRebel with NetBeans IDE and Tomcat

12.10.2012
| 30085 views |
  • submit to reddit

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).  
Published at DZone with permission of its author, Jonathan Lermitage.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Anton Arhipov replied on Mon, 2012/12/10 - 12:02pm

Great write up! However, you shouldn't spend time on setting the -javaagent option manually, instead there's a toggle button that enables jrebel agent automatically if you start the container from inside IDE.

Jonathan Lermitage replied on Mon, 2012/12/10 - 2:31pm in response to: Anton Arhipov

I have some problems with this feature, that's why I preferred not to mention it yet. But you're right :)

[edit] Okay, I have re-registered my server into NetBeans, and the javaagent flag is now automatically added. Strange, but good news.

Jonathan Lermitage replied on Fri, 2012/12/14 - 9:36pm in response to: Jonathan Lermitage

Finally, I have understood my problem : to let the JRebel plugin to add the javaagent flag automatically, the registered server's property "Use IDE Proxy Settings" has to be checked. I had unchecked it on my previous installations, that's why it didn't work.

Anton Arhipov replied on Sat, 2012/12/15 - 8:32am in response to: Jonathan Lermitage

Interesting! This is very good to know!

Matt Coleman replied on Wed, 2013/02/06 - 12:48am

JRebels in NB seems interesting i agree with Anton..will try it soon

sell sheet design 

Den Fletcher replied on Thu, 2013/02/07 - 5:18pm

 Fortunately, it's not that hard to use JRebel for your online site or applications. I have successfully used it for different modules of my holiday rentals France travel  website. There are a lot of tutorials about this and I was even able to find one specially designed for travel agencies. I am pleased with the results and I wasn't able to find any bugs so far. That's why I have recommended it ever since.

Maxime Olivier replied on Fri, 2013/05/17 - 7:57am

I hadn't validated my JRebel plugin nor checked the IDE proxy settings, thanks for the tip, now it reloads fine. I could successfully integrate it.

Hoping this feature will remain updated. Création de site
Regards from Switzerland
Maxime

Danish12 Ali replied on Mon, 2013/07/08 - 5:57am

 If you are considering purchasing Breast Actives, they offer several different packages on there site to make the process very affordable as well as they are a highly reputable company, which when it comes to your body, is something you want. haynes t-shirt

Cata Nic replied on Mon, 2013/09/02 - 4:42pm

TomCat is not the most stable solution. I've been used for an application and I was disappointed. However, your integration looks really stable and easy to use.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.