10

Hotswap code changes and save more than 40% of development time, JDK 11

 3 years ago
source link: https://blogs.sap.com/2021/12/10/hotswap-code-changes-and-save-more-than-40-of-development-time-jdk-11/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

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 changs 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.

  • 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 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 disign your solution identify all your new classes that needs to be created , create them with some emty body or minimal code and define them in the xml, then do the narmal build and doployement.
  • Once you have all the required classes loaded, then you any modify them any number of times without do hotwap without actually deployment them with narmal process.

Setup

  1. download  DCEVM JDK
    • DCEVM Opend JDK 11 from: https://github.com/TravaOpenJDK/trava-jdk-11-dcevm/releases
    • Setup DCEVM JDK as JAVA_HOME and make sure you update the path too.
  2. add below property in local.properties

    tomcat.debugjavaoptions=-XX:HotswapAgent=core  -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,address=*:5500,suspend=n
  3. Start hybris in debug mode “hybriserver.bat debug“./hybriserver.sh debug

  4. Do Remote debug from Intellij Idea or Eclipse with properties.

-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5500

Debug%20config%20in%20IntelliJ%20Idea

Debug config in IntelliJ Idea

5. Debug should be on  then do the some code changes.

created%20a%20dummy%20test%20method%20in%20home%20page%20controller

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%20modified%20classes%20%2C%20choose%20Build%20option%20in%20main%20menu.

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%20the%20classe%20reloaded%20alert

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
    • https://blogs.sap.com/2018/11/01/hotswap-with-hybris-a-free-open-source-alternative-to-jrebel/
  • 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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK