CRM and CX Blogs by SAP
Stay up-to-date on the latest developments and product news about intelligent customer experience and CRM technologies through blog posts from SAP experts.
cancel
Showing results for 
Search instead for 
Did you mean: 
As a Hybris developer, I sometimes covet how fast it is possible to see the result of a code change in a running application with interpreted languages like Python, PHP or JavaScript.
On the other hand with Hybris, it is always necessary to rebuild the source code in bytecode. Subsequently, restarting the Hybris server to load the changes.
Building Hybris project usually takes 20 minutes and restarting server on windows machine takes around 25 to 35 minutes.  Even if one-line code change is done, developer has to wait for around an hour to see the output of the changes.

What is the solution to this problem? 


Many Hyrbis developers are aware of JRebel. JRebel fast tracks Java application development by skipping the time-consuming build and server restart steps in the development process. JRebel helps developers to be more productive by viewing code changes in real time and maintaining state.
In simple words JRebel loads the code changes in the live running server, server restart is not required at all.
Problem with JRebel is, it is not free to use and pretty expensive.

Free and open source alternative to JRebel is HotSwap.

What is HotSwap? 


HotSwap is free and open source alternative to JRebel. HotSwap does exactly the same thing what JRebel does, i.e. loading the code changes directly in the running server. Server restart is not required for each code change.

In contrast to standard Java, where the HotSwap is limited to in-body code changes, the DCEVM + HotswapAgent allow following code changes:

  • Add/remove/modify class fields.

  • Add/remove/modify methods. Add/remove/modify method annotations

  • Add/remove/modify classes including anonymous classes. HotswapAgent handless correct anonymous class redefinitions.

  • Add/remove static member of classes. HotswapAgent handles static member initialization.

  • Add/remove enum values

  • Refresh framework and application server settings


Please note that Hierarchy change is still not supported in HotSwap + DCEVM.

How to Setup HotSwap agent with Hybris project? 


Step by Step guide to setup Hotswap with Hybris.

  1. Download latest release of DCEVM Java patch.

  2. To launch DCEVM on Windows: Start > cmd > right click > Run As Administrator and use: java -jar <downloaded jar file>g. java -jar installer-light.jar. Select required java installation directory from the dialog box and press “Install DCEVM as altjvm” button. Java 1.7+ versions are supported. Make sure that CMD have write access(Run as Administrator) to the java installation directory. Look at the below screenshot for reference.

  3. Download latest release of Hotswap agent jar, and put it inside your hybris/bin/platform/resources/hotswap/ (Create hotswap folder , If not present).

  4. Add the following line in the local.properties. Replace <HotswapDownlodedJarname> with the name of jar file downloaded in step number 3.


tomcat.debugjavaoptions=-XXaltjvm=dcevm -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend=n -javaagent:${platformhome}/resources/hotswap/<HotswapDownlodedJarname>=disablePlugin=Log4j2,disablePlugin=Spring,disablePlugin=Proxy,disablePlugin=AnonymousClassPatch,disablePlugin=ZK,autoHotswap=true

 

  1. Run “Ant Clean All” and restart the hybris server in debug mode.

  2. Now make changes in .java file and save it. Run “Ant build” to load the changes in the live server.


Notes:

  • autoHotswap=true, this parameter must be set to true to enable the loading of change in the running server. (autoHotswap is set true in Step 4).

  • After making the required changes .java you have two options for building the changes.

    1. Build the whole project by running “Ant build” from /bin/platform folder.

    2. Build only the extension where you have made changes by navigating inside the extension and run “Ant Build”. For Example: Navigate to /bin/customer/ext/cust_ext/ and run “Ant Build” here.

    3. Do not provide the absolute path to Javaagent, instead use {platformhome}. Absolute path to jar file may cause problems on Windows. (JavaAgent is set in Step 4).




Please let me know via comments in case you face any issue with the setup.
34 Comments