JRebel with Hybris

Follow this guide to get JRebel up and running with Hybris.

Tip

This guide assumes that you have already downloaded and activated JRebel. You can download JRebel here. Head over here for activation instructions.


Setup

To enable JRebel for Hybris, the following JVM startup parameter needs to be added to $PLATFORM_HOME/config/local.properties.

Add the following to use the JRebel Agent:

JDK Startup parameter
Windows 64-bit JDK tomcat.javaoptions=-agentpath:[c:\path\to]\lib\jrebel64.dll
Windows 32-bit JDK tomcat.javaoptions=-agentpath:[c:\path\to]\lib\jrebel32.dll
Mac OS X 64-bit JDK tomcat.javaoptions=-agentpath:[path/to]/lib/libjrebel64.dylib
Mac OS X 32-bit JDK tomcat.javaoptions=-agentpath:[path/to]/lib/libjrebel32.dylib
Linux 64-bit JDK tomcat.javaoptions=-agentpath:[path/to]/lib/libjrebel64.so
Linux 32-bit JDK tomcat.javaoptions=-agentpath:[path/to]/lib/libjrebel32.so

You can verify that JRebel is started by simply running Hybris:

./hybrisserver.sh run

Look for the following lines in the console log:

2016-11-15 12:01:51 JRebel:  JRebel Agent 7.0.0 (201611081555)
2016-11-15 12:01:51 JRebel:  (c) Copyright ZeroTurnaround AS, Estonia, Tartu.

Configuration

JRebel needs to know the location of the compiled classes. This requires additional configuration. You will need to replace $PLATFORM_HOME and $EXTENSION_NAME with your actual location values.

Extensions with web/webroot are deployed as exploded archives to the server. This means that Tomcat reads the classes from web/webroot/WEB-INF/classes for that module on startup.

  • When recompiling these extensions with ant build, no changes are required. JRebel sees the changed classes in web/webroot/WEB-INF/classes and reloads them.
  • To recompile via an IDE, you will need to change the IDE compile output path to web/webroot/WEB-INF/classes.

Backoffice extensions that are packaged as JAR files need a descriptor file called rebel.xml. This XML file will tell JRebel that the .class files for this JAR are in that folder. To achieve this, you will need to do the following for all extensions you want reloaded:

  • To recompile via an IDE, set the compile output to where the classes are actually compiled to with ant build. For backoffice extensions, this would be $PLATFORM_HOME/bin/custom/$EXTENSION_NAME/backoffice/classes.

  • Create the following rebel.xml in $EXTENSION_NAME/backoffice/resources:

    <?xml version="1.0" encoding="UTF-8"?>
    <application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_1.xsd">
      <classpath>
        <!-- Make sure to replace $PLATFORM_HOME and $EXTENSION_NAME with your concrete values -->
        <dir name="$PLATFORM_HOME/bin/custom/$EXTENSION_NAME/backoffice/classes"/>
      </classpath>
    </application>
    
  • Edit $EXTENSION_NAME/buildcallbacks.xml and add the following before build callback:

    <macrodef name="$EXTENSION_NAME_before_build">
      <sequential>
        <mkdir dir="${ext.$EXTENSION_NAME.path}/backoffice/classes" />
          <copy file="${ext.$EXTENSION_NAME.path}/backoffice/resources/rebel.xml" todir="${ext.$EXTENSION_NAME.path}/backoffice/classes/" failonerror="false" />
      </sequential>
    </macrodef>
    

    This will make sure that rebel.xml is bundled into the compiled extension JAR file on build.

When changing classes from the IDE, just recompile the class (either with ant build or via the IDE after setting the correct compile output) and reload the browser. The changed .class files are picked up by JRebel and reloaded on the fly. For more details, refer to JRebel’s online documentation at http://manuals.zeroturnaround.com/jrebel/index.html.