Boost your eXo Platform Development with JRebel!

JRebel is a tool that enables developers to instantly reload changes in Java sources files, without having to redeploy the application or restart the server. In this tutorial, we will demonstrate how to use JRebel to speed up development with eXo Platform. JRebel integrates well with Eclipse, which we used in the following example. To learn how to start eXo Platform in Eclipse, check out this tutorial.

Install JRebel in Eclipse

The first step is to install JRebel in Eclipse. Simply follow the first 3 steps in this tutorial on the JRebel website.

New Portlet Project

Before going further with JRebel, you need to create a new portlet project:

  • Go to File > New > Project…
  • Select Maven > Maven Project
  • Check Create a simple project (skip archetype selection)
  • Click Next
  • Fill maven information. For example:
    • Group ID: org.exoplatform
    • Artifact ID: jrebel.portlet
    • Version: 1.0.0-SNAPSHOT
    • Packaging: war
    • Name: Portlet with JRebel
    • Description: Portlet with JRebel
  • Click Finish

Once created, you can add the source file for the portlet:

src/main/webapp/WEB-INF/web.xml

src/main/webapp/WEB-INF/portlet.xml

src/main/java/org/exoplatform/jrebel/portlet/MyPortlet.java

pom.xml

Add the portlet 2.0 dependency:

src/main/webapp/view.jsp

src/main/webapp/help.jsp

You should now have the following project:
Portlet Sources Tree

In order to deploy your project to a server, it must have the “Dynamic Web Module” facet. This can be done in the project’s properties, in the Project Facets item. Once this is completed, check the Dynamic Web Module item and select version 2.5 (and 1.6 for Java). Finally, declare the src/main/webapp folder as part of the web application structure in the section Deployment Assembly of the project’s properties:

Web Deployment Assembly

On this screen, you can declare all the resources you want to push to the web application on your server.

Configure the Project to Use JRebel

The next step is to make JRebel aware of your project:

  • Right-click on the project > JRebel > Add JRebel Nature
  • Right-click on the project > JRebel > Generate rebel.xml
  • select the src/main/resources folder

Open the rebel.xml. You can see that JRebel will monitor all the folders pushed to your web application on the server, including the Java source files in target/classes and the files in src/main/webapp:

Configure the Server to Use JRebel

The server declared in Eclipse must also be configured to take use JRebel:

  • Go to the Servers view in Eclipse
  • Double-click on your eXo Platform server
  • In the JRebel integration section, check the Enable JRebel agent checkbox
  • Be sure to disable the Automatic Publishing in the Publishing section (the Never publish automatically must be checked)

Server Configuration

Publish the Portlet in the Server

We are now ready to deploy your portlet:

  • Right-click on the server > Add and Remove…
  • Select the project and click Add
  • Click on Finish
  • Start the server

After the server is started, you can add your portlet to a page and see the “Hello World !” text:
Portlet Helloworld

JRebel in Action!

To see JRebel in action, change the portlet class. For example, add a new request attribute to be used in the JSP:

and in the view.jsp:

Portlet Helloworld Reloaded

Your changes have been applied without redeploying the webapp. You should only see this in the logs:

Cool, isn’t it? 😉

JRebel supports most of the changes that are possible in your Java classes, including changes to method bodies, adding/removing constructors/methods/fields/classes/annotations, and more.

What about Services?

In eXo Platform, you occasionally need to create services and deploy them as jar files in the server, which almost always requires a restart. With JRebel, you no longer have to perform time-consuming server restarts for every new or updated service.

As you did with the portlet, create a new maven project. Add the JRebel Nature, and generate the rebel.xml file in src/main/resources. The other steps (Dynamic Web Module facet, …) are not necessary since it is not a webapp.

Next, create a new eXo service by following the example described in this tutorial. After completing the steps (add the eXo dependency in pom.xml, create the class and add the configuration.xml in src/main/resources), you are now ready to deploy the service. The first deployment will require a restart, so build your maven project, stop your eXo Platform server, copy the jar file in the lib folder of the server, and restart the server.

Once started, the URL /portal/rest/user/name/thomas returns the message “Hello thomas!”. Change the service class, for example :

Simply call the same URL again, and you’ll see the message “Welcome in the JRebel world thomas!”.

Conclusion

Using JRebel in development will save you a lot of redeployments and restarts. The only limitation is that you can’t reload the eXo configuration this way. Oh, and I see another drawback: you won’t be able to use all that “server restart time” as an excuse to take a coffee break anymore 😉

Related Posts
2 Comments
Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">