Overview
Standard Java Hotswap is limited to in-body code changes, But DCEVM + Hotswap agent allows you to Hotswap addition, removal and modification of following changes for Java classes.
- class fields,
- methods
- anonymous classes
- static members
- Enums
What it will not support:
- Addition or removal of Annotation change the super class or interface. XML changes
Benefits of DCEVM in Hybris.
- Building the code, starting the server takes average 12 to 20 mins, depending on no of extensions you have and speed of the system.
- DCEVM saves all these build and deployment timing from these many minutes to seconds, if you have changes only in java files.
- And when you are able to test your changes within a seconds, there is fair chance that you can spend good amount of time in unit testing, that means a less bugs and better code quality.
For any XMl changes and New classes:
- In case if you have to do changes in XML files and there is need to create a new class etc, then
- I suggest whenever you start your day for the work, create a design your solution identify all your new classes that needs to be created , create them with some empty body or minimal code and define them in the XML, then do the normal build and deployment.
- Once you have all the required classes loaded, then you any modify them any number of times without do Hotswap without actually deployment them with normal process.
Setup
- download DCEVM JDK
add below property in local.properties
tomcat.debugjavaoptions=-XX:HotswapAgent=core -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,address=*:5500,suspend=n
Start hybris in debug mode "hybriserver.bat debug" "./hybriserver.sh debug"
- Do Remote debug from Intellij Idea or Eclipse with properties.
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5500
Debug config in IntelliJ Idea
5. Debug should be on, then do some code changes.
created a dummy test method getMessage3() in home page controller while debug is on.
6. Compile only that class , within seconds it will do that job
build modified classes , choose Build option in main menu.
7. Now this class gets recompiled and the changes gets loaded in the server, and when you refresh the home page you should be able to see message from new method getMessage3() created newly in the console.
See the classe reloaded alert
In Summary:
- To setup DCEVM, you just need to download DCEVM JDK and set it as your JAVA_HOME
- Add additional property in your local.properties
- Start the server in Debug mode
- Start Remote debug in your faveraout IDE
- Recompile the modified classes to get them reloaded in the server to save the time of building and restarting the hybris server. Thats it.
Points to be Noted :
- Setup is for JDK 11,
- Tested for Hybris 2105, But should work any version which is based JDK 11.
- We have to use DCEVM Open JDK instead of Standard JDK 11.
- Eclipse or Intellij Idea.
- For Setup for JDK 8 , you can refer
- you can try "ant build" command instead of recompiling from IDE
Thanks for your time, Comments and suggestions are welcome, If any one using docker, we can do this from docker too, I will share those details next time.