Skip to Content
Product Information

HotSwap with Hybris: free open source alternative to JRebel

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.

10 Comments
You must be Logged on to comment or reply to a post.
  • This is really awesome, We were facing lot of troubles in our project due to restarting of server every time we make a change. And for some reasons we didn’t wanted to setup Jrebel. But this approach solved our problem real quick and easily. The best part is how easy it is to set it up. Thanks a lot 🙂

  • I highly recommend everybody developing SAP (Hybris) Commerce to use IntelliJ IDEA Ultimate + hybris Integration Plugin

    (The license cost of IntelliJ is easily justified by the increased productivity)

    Because the plugin enables you to correctly build the platform inside IntelliJ, you can omit autoSwap=true from the hotswap agent configuration and just attach the debugger (which the plugin also pre-configures for you) to the running instance.

    If you do so, you can just edit and compile inside IntelliJ, and the classes are automatically reloaded.

     

    • Thanks for your comment.

      Only problem with IntelliJ is: it is not free. Please do note that, the same can also be achieved in Eclipse also. Working on plugin will write a blog again after I successfully complete it.

      Idea behind this motive is to enable everyone to learn Hybris without spending a dime.

      When I was ramping up on Hybris, I didn’t have JRebels, IntelliJ  and not even a MAC. I was suppose to buy license only when a real Hybris project comes in.

       

    • Hello Markus,

      Could you, please, share how is your configuration of IntelliJ and HotSwap, I did not understand very well, your comment about the debugger.

      We have seen that IntelliJ together with the Hybris plugin, works great for the compilation and construction of the classes and avoid the use of ant, so we already saved a lot of time, nevertheless we lack the step of the deploy and the stopped and restart of the server

      In our project we already have the IntelliJ license but we do not have a budget for JRebel

       

      Thanks a lot!

  • Hi Suleman,

    Thanks for such a useful blog.

    I just have one question, I observed that my hybris storefront has started working slow after this installation as there are so many background activities for hotswap. Do you think this might be the reason for the slowness?

    • Hi Sugandha,

      Thanks for your comment.
      I suppose that logs are not the cause of slowness. HotSwap does not run any such background activities which will slow down the storefront.

      Please check the following thing if hybris and hotswap is running slow: 

      • You are not using obsolete JVM version. Prefer using Java version 8 or greater.
      • Check these javaoptions, if sufficient resources are allocated:
      -XX:PermSize=
      -XX:MaxPermSize=
      -XX:+UseParallelGC
      -Xms
      -Xmx
      

       

  • Hi Suleman,

    Thank you very much for the effort. This blog has really reduced effort for development. My project took 1 hour to build and 1.5 hour for server startup. My entire team has started using hotswap as Jrebel is too costly.

  • Hi Suleman,

    Thank you very much for this post. It helped me a lot in development.

    For others, information from Suleman as well:

    If you have this kind of exception when you try to access storefront:

    SEVERE: Servlet.service() for servlet [DispatcherServlet] in context with path [/yacceleratorstorefront] threw exception [org.apache.jasper.JasperException: Unable to compile class for JSP] with root cause java.io.IOException: classFile.delete() failed

     

    Do the following:

    • Delete Work directory of Tomcat i.e hybris\bin\platform\tomcat\work ( take a backup before deleting)  and run Ant clean all

    • start your server with hotswap

    • this should fix your problem 🙂