JavaRebel and Jersey

I have been playing with JavaRebel (thanks for the tip Kohsuke!) and Jersey. JavaRebel:

reloads changes to Java classes on-the-fly without redeploy or restart including new methods and fields. It is a generic solution that works for standalone Java applications as well as application servers

I opened the HelloWorld example provided in the Jersey distribution and modified the run.jvmargs property in the nbproject/project.properties file to be:

run.jvmargs=-noverify -javaagent:<dir>/javarebel.jar

ran the project and verified with curl the response to a GET request.

Then i modified the String returned by the HTTP GET method of the HelloWorldResource recompiled the project and verified the response to the GET request had changed. (I wish NetBeans had an automatic compile option.)

It is also possible to integrate with Glassfish (although i have not tried it). Add the following snippet of XML as a child of the <java-config> element in a domain.xml:

<jvm-options>-noverify</jvm-options>
<jvm-options>-javaagent:<dir>/javarebel.jar</jvm-options>

A very nice and easy integration. Clever stuff! I wonder how it is done...

Unfortunately it is not possible to modify the annotations, method signatures, add new methods, or add new resource classes. Jersey creates, for performance reasons, a runtime model of a resource so it does not have to analyze the annotations using Java reflection every time. Jersey has no way of knowing if a resource class has been created, modified or deleted. (I suppose it is the same for any framework that caches information about classes, for example JAXB.) 

If there was a way to detect changes i think it would be easy to modify Jersey to update its runtime model accordingly (an API for listening to such changes seems useful independently of JavaRebel). And then it would make a rather nice rapid development platform for Jersey development.

Comments:

I've been trying it out with JBoss AS 4.2, and it's working pretty well there too.

Although sensing changes would be nice (and quite likely possible with Java 6 on many operating systems, using system calls), the other somewhat helpful change that isn't necessarily easy, but would be a sign of excellent architectural strategy, is for libraries such as Jersey and similar (Hibernate, etc.), to provide a refresh or reload feature, so in the least we could tell the system to refresh.

Posted by Marcus on January 04, 2008 at 05:13 PM CET #

Paul, we are working right now on JavaRebel 1.1, which will both propagate annotation changes and provide notifications on class changes. Will it be possible to update the runtime model then?

Posted by Jevgeni Kabanov on January 09, 2008 at 06:25 AM CET #

Hi Jevgeni,

Good to hear that.

Jersey does not yet contain an API and implementation to listen to class changes and update the runtime model but i definitely want to do this (it should not be hugely difficult, famous last words!).

When will JavaRebel 1.1 be ready? i could try and sync up any work i do with your time-frame.

Paul.

Posted by Paul Sandoz on January 09, 2008 at 06:44 AM CET #

We are likely to have a usable beta up in February. January is a bit of a slow month for us.

Posted by Jevgeni Kabanov on January 11, 2008 at 03:19 AM CET #

The SDK is available here (for some time, actually): http://code.google.com/p/zt-oss/. Here's a by-example how-to of reacting to changed classes.

Posted by Jevgeni Kabanov on March 23, 2008 at 03:11 PM CET #

Forgot the second link: http://code.google.com/p/zt-oss/wiki/GuiceZeroTurnaroundConversion.

Posted by Jevgeni Kabanov on March 23, 2008 at 03:12 PM CET #

Hi Jevgeni,

Many thanks. I will try and give this a go for the Jersey 0.7 release scheduled for April 18th.

Paul.

Posted by Paul Sandoz on March 25, 2008 at 04:09 AM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
About

sandoz

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today