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.

/
30 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 🙂

     

     

  • Hello Suleman thanks a lot for a useful blog

    I have 2 questions, please,

    1. can I use a hotswap with servers like tomcat, jboss, glassfish.. or I should use a specific server

    2. Hybris server is an application server?

    • Hi Khalil,

      Yes, you can use with other application servers also, please check the documentation.

      Hybris server is an application server.

    • I would like to understand how HotSwap works with the modifications that we made in Spring, so far every time we add some bean in * spring.xml, * items.xml or in * beans.xml we must build, stop and start our server so those changes take effect.

      Do we have some incorrect configuration?

      This is the line that we have configured in our local.properties:

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

       

      Thanks a lot!

  • Hello Suleman,

    Could you please tell me whether it will work with java 1.6 or not? And if i want to work with java 1.6 what i need to do?

     

  • Hello Suleman,

    when i start Hybris, i get the following warnings. What does it means?

     

    I use Windows 10.

     

    STATUS | wrapper | main | 2019/06/04 09:15:57.329 | –> Wrapper Started as Console
    STATUS | wrapper | main | 2019/06/04 09:15:57.340 | Java Service Wrapper Professional Edition 64-bit 3.5.29
    STATUS | wrapper | main | 2019/06/04 09:15:57.340 | Copyright (C) 1999-2016 Tanuki Software, Ltd. All Rights Reserved.
    STATUS | wrapper | main | 2019/06/04 09:15:57.341 | http://wrapper.tanukisoftware.com
    STATUS | wrapper | main | 2019/06/04 09:15:57.342 | Licensed to SAP SE for hybris Platform
    STATUS | wrapper | main | 2019/06/04 09:15:57.342 |
    WARN | wrapper | main | 2019/06/04 09:15:58.647 | The ‘{X-Real-IP}i ‘ environment variable was referenced but has not been defined.
    WARN | wrapper | main | 2019/06/04 09:15:58.647 | The ‘u ‘ environment variable was referenced but has not been defined.
    WARN | wrapper | main | 2019/06/04 09:15:58.648 | The ‘r ‘ environment variable was referenced but has not been defined.
    WARN | wrapper | main | 2019/06/04 09:15:58.649 | The ‘b ‘ environment variable was referenced but has not been defined.
    WARN | wrapper | main | 2019/06/04 09:15:58.649 | The ‘{User-Agent}i ‘ environment variable was referenced but has not been defined.
    WARN | wrapper | main | 2019/06/04 09:15:58.650 | The ‘{JSESSIONID}c proto:’ environment variable was referenced but has not been defined.
    STATUS | wrapper | main | 2019/06/04 09:15:58.754 | Launching a JVM…

    • Hi Mechael,

      Have you solved the problem for release 1905 and SAP machine 11 ? I just had to create dcevm folder inside JDK lib folder and copy the libjvm.dylib from lib/server to lib/dcevm. 

       

      Thanks,

      Prakash

  • Suleman Mohd

    I’ve encountered some problems with the GC:

    1. Must use the serial GC in the DCEVM
    2. Conflicting collector combinations in option list

    If someone encounters the same problem, adding this java options will solve it:

    -XX:-UseParNewGC -XX:-UseConcMarkSweepGC -XX:+UseSerialGC
  • Hi Suleman Mohd,

     

    Thanks for this wonderful documentation. I am facing an issue while performing an “ant build” after compiling the code. The server is restarting everytime i do an “ant build”

     

    If you know something about this phenomenon pls share.

     

    Thank you.

  • Hi Suleman,

    Thanks for the clear documentation. I am also facing issue like after ant build compiling code and the server restarting every time.

     

    If you know something please share your thoughts.

     

    Thanks,

  • Hi Suleman,

     

    I followed the instructions above. When running the hybrisserver.bat debug command, i’m getting the error message

    HOTSWAP AGENT: 10:47:33.839 ERROR (org.hotswap.agent.config.PluginRegistry) – Error in plugin initial processing for plugin package ‘org.hotswap.agent.plugin’

     

    Environment:

    java version “1.7.0_80”
    Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
    Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)

    Hybris: 5.2

    installed DCEVM as altjum: Yes(24.79-b02-dcevmlight-3)

    Any guidence would of great help, thank you.

     

  • I have followed the same steps to install altjvm and use hotswap and the hybris server is starting properly, but for the first time, the ant clean all is taking about 30 minutes and the server start up is taking about 40minutes. For any change in facades or populators, the change is getting reflected by building only the required extension.

    But the issue is with the storefront extension. Whenver any change is made in the storefront extension, I’m getting “Unable create CtClass for URI ‘*_tag.class'” error for all the tag files and the pages are not opening after that.

    Hybris Version used: 6.7

    DCEVM version: DCEVM-8u181-installer-build2.jar

    java version: “1.8.0_191”

    OS: Windows 10 pro.

    If you know something about this issue, please let me know.

    • Yep, I have just installed dcevm/hotswap yesterday and I’m facing the same issue.

       

      whenever changing/building storefront, it enters a rabbit hole of registering directory and attempting rewave…

      During this process, the application don’t respond. Eventually it does, but it takes a really long time (somewhat near the deploy process) , I belive it’s re-deploying the entire application again.

       

      I have no idea why as well

       

      Suleman Mohd , any ideas?

       

       

       

       

       

  • Great article, Suleman!
    But I’m using the Hybris version 1811, and this hotswap instalation doesn’t works.
    The server starts (even showing the error below), but does not compile the code after the ‘ant build’ command.
    Do you have any idea what the reason would be?

     

    Environment:

    java version “1.8.0_181”
    Java(TM) SE Runtime Environment (build 1.7.0_181-b13)
    Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)

    Hybris: 1811

    installed DCEVM as altjum: Yes (25.71-b01-dcevmlight-26)

     

    error:

     

    HOTSWAP AGENT: 17:49:01.929 INFO (org.hotswap.agent.config.PluginRegistry) – Plugin ‘org.hotswap.agent.plugin.hotswapper.HotswapperPlugin’ initialized in ClassLoader ‘HybrisWebappClassLoader
    context: previewwebservices
    delegate: false
    ———-> Parent Classloader:
    de.hybris.bootstrap.loader.PlatformInPlaceClassLoader@17974a37
    ‘.
    HOTSWAP AGENT: 17:49:01.929 INFO (org.hotswap.agent.config.PluginRegistry) – Plugin ‘org.hotswap.agent.plugin.tomcat.TomcatPlugin’ initialized in ClassLoader ‘HybrisWebappClassLoader
    context: previewwebservices
    delegate: false
    ———-> Parent Classloader:
    de.hybris.bootstrap.loader.PlatformInPlaceClassLoader@17974a37
    ‘.
    HOTSWAP AGENT: 17:49:01.929 INFO (org.hotswap.agent.plugin.tomcat.TomcatPlugin) – Tomcat plugin initialized – Tomcat version ‘8.5.32.0’

     

     

     

    • Josenildo Melo 

      those doens’t seems like errors, mostly because they are under INFO.

       

      What do you mean by ”but does not compile the code after the ‘ant build’”?

      Explain me what the process you’re attempting to do.

       

      I`m using the same hybris version and the only issue I’m facing is building the storefront project, which re-deploys the entire application

  • Well, HotSwap is promissory. However, the community is barely non existent, so if you face a issue, you’re basically on your own. And that sucks!