Wednesday, September 21, 2011

Using JRebel from pure Maven in a web application

Hi there folks!

I'm sure you've read every bit and piece about how to bend Maven to do your bidding. This time I'm most probably going to duplicate a lot of stuff found on other sites but I'm simply sick and tired of looking it up every single time I need it. We're going to configure a Maven web application project to run under Jetty (mvn jetty:run) with JRebel to do the reloading. So let's get started!

Installing Maven and JRebel

That one is a no brainer but for the sake of completeness I list this particular step here as well.

The pom.xml

The pom.xml file we're going to use looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">



  <name>Example Web application</name>

    <!-- stop stuppid Maven message about build being platform-dependant -->

      <!-- make sure we're using Java 1.6 and not some stone age version -->
      <!-- enable jetty:run mojo -->
      <!-- enable generation of jrebel.xml - needed for the agent -->

Running Maven with JRebel

You need to specify the javaagent as JRebel in order for the class-reloading to work. You do that by extending the environment variable MAVEN_OPTS with the following:
set MAVEN_OPTS=-javaagent:C:\progra~1\ZeroTurnaround\JRebel\jrebel.jar %MAVEN_OPTS%
With that in place run mvn jetty:run or mvn tomcat:run and you're all set!

Doing reloading

Please bare in mind that Maven is not Eclipse! When you save a file it doesn't automatically recompile it so in order for the modified class to be reloaded you need to recompile the project using mvn compile!

Well that pretty much summarizes it. It's not very difficult to setup as you see here but there are steps that are not described all in one place so here it is for your entertainment :)

Have fun!


mcahornsirup said...

I do not get it - what is the benefit of JRebel in this case?

Matthias Hryniszak said...

You obviously didn't try JRebel yet. The default class reloading mechanism in Java is like a bike compared to JRebel being a Rolls Royce.

Plus I'm always looking for ways to work without Eclipse or NetBeans because they are on many occasions slowing me down. So here I can develop a web application without Eclipse and have full-blown class reloading.

johnnyJohn said...

uhhhh the one who said "I'm always looking for ways to work without Eclipse or NetBeans because they are on many occasions slowing me down" is just a newbie. It remind me a decade ago when some argued against IDE and saying Notepad is a must.
Obviously, those never have develop real large apps of any kind..

Matthias Hryniszak said...

I soooo waited for someone to pick up on that :)

I have years of experience with what you called "real large apps" and I hate them with a passion. As long as you have the technical capabilities you will bend towards the dark side and produce unmanageable, ugly large blobs that you called "real large apps". I have way to many examples of that happening throughout the last 15 or so years.