## Sunday, October 30, 2011

### JDeveloper: Setting up JRebel with JDeveloper 11g

The following provides a quick walkthrough on how to enable JRebel for a JEE web project in the Oracle’s JDeveloper IDE. JDeveloper version 11g was used for creating this tutorial, but other versions are expected to work similarly.

Now you just need a web application and to enable JRebel for it. To do it, two steps are necessary:
1. enabling JRebel in application server’s launch configurations for the current web-app
2. adding the JRebel’s project-specific configuration file (rebel.xml) into your project’s classpath

0. Creating a web project
This is the “step 0″ as probably you’ll want to enable JRebel for a web project you already have. Anyway, for this tutorial we created a demo application with the Create Web Project wizard (right click in Application Navigator,New .. -> General -> Projects -> Web Project).
To demonstrate JRebel working, a servlet and a JSP page were added to the project. While adding a JSP page was a matter of checking the “include JSP page” box during the web project creation, adding a servlet was just as easy by right-clicking on the project name (in Projects navigator) -> New.. ->Web Tier -> Servlets -> HTTP Servlet. We should now have a project structure something like the following:

# 1. Enabling JRebel in app-server’s launch configuration

First you need to tell the IDE to start the application server (WebLogic by default) with the JRebel’s javaagent. Go through the following steps:
1. Right-click on your project in the Application Navigator, open Project Properties..
2. Open the Run/Debug/Profile tab
3. Open the edit dialog for the chosen run configuration (click Edit..)
4. In the Launch Settings tab, edit the Java Options. Append all the desired configuration options for JRebel. The minimal install string is: -noverify -javaagent:C:\path\to\jrebel\jrebel.jar, where the javaagent path is adjusted according to your local JRebel installation path.

Verification: When you start your application on the application server (by right-clicking on your servlet-file or your JSP-file and hitting Run..) for the first time and observe the server log, you have to see a large JRebel banner near the beginning of the server log. Something like this:

...
starting weblogic with Java version:
Starting WLS with line:
/home/sander/apps/oracle-jdev/jdk160_18/bin/java -client   -Xms256m -Xmx512m ...

#############################################################

JRebel 4.5.1
(c) Copyright ZeroTurnaround OU, Estonia, Tartu.

Over the last 1 days JRebel prevented
at least 9 redeploys/restarts saving you about 0.4 hours.

This product is licensed to Mohamed Mahmoud Taman.
for non-commercial use only.

The following plugins are disabled at the moment:
* Grails Plugin (set -Drebel.grails_plugin=true to enable)
...
#############################################################

Server startup options can also be modified in the server’s Properties view accessed through the Application Server Navigator, but this doesn’t seem to work. The configuration dialog also includes a warning that these settings are used only when starting the server without any application selected… anyway, somehow the settings are not picked up and the server starts up without JRebel (you know it by seeing no JRebel banner in the beginning).

# 2. Creating the rebel.xml configuration file

You also need to create a project-specific JRebel configuration file (rebel.xml) to tell JRebel which locations to monitor for the updated versions of class files and other resources. The rebel.xml descriptor needs to end up in your project’s classpath (under WEB-INF/classes).
Probably the quickest is to right-click on Application Sources, pick New.. -> All Items -> File. For further information on rebel.xml configuration file refer to the appropriate documentation; anyway, here’s an example:

 <?xml version="1.0" encoding="UTF-8" standalone="no"?> <application> <classpath> <dir name="/home/sander/dev/jdeveloper/DemoProject/classes" /> </classpath> <web> <link target=""> <dir name="/home/sander/dev/jdeveloper/DemoProject/public_html" /> </link> </web> </application> 
The two things here are the path to the directory where your IDE compiles the classes and the path to the directory where your IDE constructs the so-called “web root” directory (i.e. a directory that contains mostly the same things as the war-file after extracting). It is not important that the web root directory also contains the WEB-INF/classes and WEB-INF/lib directories, as the classes are picked up from the path in the <classpath>and libraries are not expected to change.
The path to where JDeveloper is building the classes is defined by the Output Directory setting in the Project Properties -> Project Source Paths view; the default value for it is $PROJECT_ROOT/classes. The web root of the web project should also be located directly in the project’s root directory; by default it is$PROJECT_ROOT/public_html.

Run the application on the server to test whether JRebel has been set up properly. In our case, the easiest is to direct our browser to the URL where the auto-generated servlet is just outputting some HTML:

 public class Servlet1 extends HttpServlet { // .. public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType(CONTENT_TYPE); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head><title>Servlet1</title></head>"); out.println("<body>"); out.println("<p>The servlet has received a GET. This is the reply.</p>"); out.println("</body></html>"); out.close(); } } 

Obviously, without JRebel’s code reloading, changing anything in this Java code wouldn’t be seen in the browser until we redeploy. Convince yourself that recompiling the edited servlet results in the output also changing in the browser after hitting F5 (if you did configure everything correctly).

Thanks JRebel development and blog for information.