The largest Interview Solution Library on the web


« Previous | 1 | 2 | 3 | Next »

Rest - JRebel support


Table of Contents

9.1. How to use JRebel with Jersey
9.2. Using JRebel with the hello world sample
9.3. Limitations

Jersey provides basic support for JRebel. JRebel can be used to reload java classes at runtime without requiring to redeploy an application. This can improve developer productivity. Java source can be modified, recompiled, and JRebel will ensure changes will be reflected at runtime.

JRebel isn't opensource and is not for free BUT Zeroturnaround (JRebel's author) provides a free license for open source project developers. More details can be found on the project website: http://zeroturnaround.com/jrebel. Jersey currently supports JRebel version 3.1.2.

9.1. How to use JRebel with Jersey

The jersey-jrebel dependency is required in the pom file:

<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-jrebel</artifactId>
<version>1.9</version>
</dependency>

The javarebel-maven-plugin plugin can be added to the pom to automatically configure JRebel for the case when java is executed from maven:

<plugin>
<groupId>org.zeroturnaround</groupId>
<artifactId>javarebel-maven-plugin</artifactId>
<executions>
<execution>
<id>generate-rebel-xml</id>
<phase>process-resources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>

9.2. Using JRebel with the hello world sample

The following assumes that JRebel has been set up correctly (a JRebel informational message will be output if JRebel is enabled).

Download the hello world sample and modify the pom file in accordance with the prevous chapter.

Compile Helloworld sample with mvn clean install and run it with mvn exec:java. The Helloworld application is deployed on Grizzly container.

Use a browser and goto the following URL http://localhost:9998/helloworld. Messages should be output indicating initialization of Jersey framework, and the browser should display Hello World.

Modify the HelloWorldResource.java file such that the resource method getClichedMessage returns a different String value. Run mvn compile. Reload the browser window and the browser should display the modified message.

9.3. Limitations

JRebel currently doesn't notify it's plugin about newly created classes that have no reference to existing classes, such as newly created resource or provder classes. However, its possible to detect a newly created resource class and use it in your application when you are doing some other changes to existing code. Why? After a change has beed made, Jersey re-initializes itself and the new class can be detected in the process. For this case you you have to use class or package scanning for detecting such resource classes.

« Previous | 1 | 2 | 3 | Next »


copyright © 2014 - all rights riserved by javatechnologycenter.com