JRebel with SAP Commerce (Hybris)¶
Follow this guide to get JRebel up and running with SAP Commerce (Hybris).
Tip
This guide assumes that you have already downloaded and activated JRebel. You can download JRebel here. Head over here for activation instructions.
The steps include:
Startup configuration - adding JRebel Agent to your server runtime.
Project configuration - creating rebel.xml configuration files to specify which folders JRebel should monitor for changes.
Startup configuration¶
To enable JRebel for SAP Commerce (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 |
|
Windows 32-bit JDK |
|
Mac OS X 64-bit JDK |
|
Mac OS X 32-bit JDK |
|
Linux 64-bit JDK |
|
Linux 32-bit JDK |
|
Tip
Run the command ant all after changing the properties file to apply the new configuration!
You can verify that JRebel is started by simply running SAP Commerce (Hybris):
./hybrisserver.sh run
Look for the following lines in the console log:
2024-04-02 14:23:55 JRebel: JRebel Agent 2024.1.0 (202001051049)
2024-04-02 14:23:55 JRebel: (c) Copyright 2007-2024 Perforce Software, Inc.
Project configuration¶
Configuring most modules¶
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.
Exception: configuring the backoffice extensions¶
Backoffice extensions are different from all other modules, as they are deployed as packaged JAR files. To enable reloading for this scenario, a configuration file called rebel.xml must be provided. rebel.xml will tell JRebel where to look for updated versions of the .class files for this JAR.
Newer versions of SAP Commerce (Hybris) 6.x and later can automatically generate a suitable rebel.xml for all backoffice extensions.
To enable this functionality, open the $PLATFORM_HOME/bin/platform/resources/ant/compiling.xml build script and find this line:
<jar destfile="${ext.@{extname}.path}/resources/backoffice/@{extname}_bof.jar" basedir="${ext.@{extname}.path}/backoffice/classes" excludes="**/rebel.xml"/>
Remove exclusion of rebel.xml configuration files, i.e. replace the line with the following:
<jar destfile="${ext.@{extname}.path}/resources/backoffice/@{extname}_bof.jar" basedir="${ext.@{extname}.path}/backoffice/classes" />
This will make sure that rebel.xml is bundled into the extension JAR file on build.
Exception: configuring backoffice extensions with SAP Commerce (Hybris) 5.x¶
For older SAP Commerce (Hybris) versions it is necessary to manually add the rebel.xml files.
Start by modifying the compiling.xml as described above.
Next, do the following for all the backoffice extensions that you want to use with JRebel.
Make sure to replace $EXTENSION_NAME in the snippets below with your actual extension name.
Create a
rebel.xmlfile in$EXTENSION_NAME/backoffice/resourceswith the following content:<?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> <!-- replace $EXTENSION_NAME below with your actual extension name --> <dir name="${HYBRIS_BIN_DIR}/custom/$EXTENSION_NAME/backoffice/classes"/> </classpath> </application>
Edit the
$EXTENSION_NAME/buildcallbacks.xmlfile and add the following as a child of theprojectelement:<!-- replace $EXTENSION_NAME below with your actual extension name --> <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>
Building and reloading changes¶
After making changes to source files, just recompile and reload the browser. The changed .class files are picked up by JRebel and reloaded on the fly.
When recompiling modules from command line with
ant build, no changes are required. For backoffice extensions, the build locations should now be mapped byrebel.xml. For other modules, JRebel sees the updated classes inweb/webroot/WEB-INF/classesand reloads them.
Tip
If you are modifying just one module, rebuild only the respective module for a faster build time.
To recompile in the IDE, set the compile output to where the classes are actually compiled to with
ant build:
For backoffice extensions, change the IDE compile output path to
$PLATFORM_HOME/bin/custom/$EXTENSION_NAME/backoffice/classes.For all other modules, change the IDE compile output path to
web/webroot/WEB-INF/classes.
Tip
If you use IntelliJ, the SAP Commerce (Hybris) IntelliJ plugin will make it much easier to properly set up building in the IDE.
Debugging with JRebel¶
To enable JRebel for SAP Commerce (Hybris) while debugging, the following JVM startup parameters need to be added to $PLATFORM_HOME/config/local.properties. We recommend using the JRebel IDE plugins for the best debugging experience.
Add the following to use the JRebel Agent while debugging:
JDK
Startup parameter
Windows 64-bit JDK
tomcat.debugjavaoptions=-agentpath:[c:\path\to]\lib\jrebel64.dllWindows 32-bit JDK
tomcat.debugjavaoptions=-agentpath:[c:\path\to]\lib\jrebel32.dllMac OS X 64-bit JDK
tomcat.debugjavaoptions=-agentpath:[path/to]/lib/libjrebel64.dylibMac OS X 32-bit JDK
tomcat.debugjavaoptions=-agentpath:[path/to]/lib/libjrebel32.dylibLinux 64-bit JDK
tomcat.debugjavaoptions=-agentpath:[path/to]/lib/libjrebel64.soLinux 32-bit JDK
tomcat.debugjavaoptions=-agentpath:[path/to]/lib/libjrebel32.soAdd the
tomcat.debugjavaoptionsvalue to your$PLATFORM_HOME/bin/platform/project.propertiesfile. It should also include-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000, otherwise the JVM will not start in debug mode.Example:
tomcat.debugjavaoptions=-agentpath:c:\jrebel\lib\jrebel64.dll -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000
Tip
Run the command ant all after changing the properties file to apply the new configuration!
You can verify that JRebel is started by running SAP Commerce (Hybris) with the debug command:
./hybrisserver.sh debug
Look for the following lines in the console log:
2024-04-02 14:23:55 JRebel: JRebel Agent 2024.1.0 (202001051049)
2024-04-02 14:23:55 JRebel: (c) Copyright 2007-2024 Perforce Software, Inc.