Select Page

Avoid infamous change – restart – wait – check development lifecycle!

Avoid infamous change – restart – wait – check development lifecycle!

Stop waiting for build & deploy make code changes. Write code and refresh your browser!

Use DCEVM and add java fields, methods, classes and use them without restarting your application server, it’s a modification of the HotSpot VM that allows unlimited class redefinition at run-time. You can add/remove fields and methods and change the super types of a class at run-time. The features of DCEVM are likely to be integrated in a future update of #Java 8 as part of JEP 159.

View code changes instantly and increases team velocity!

          DCEVM                  JVM Hot Swap         
Changes to method bodies yesyes
Adding/removing Methods yes no
Adding/removing constructors yes no
Adding/removing fields yes no
Adding/removing classes yes no
Adding/removing annotations yes no
Changing static field value yes no
Adding/removing enum values yes no
Modifying interfaces yes no
Replacing superclass yes no
Adding/removing implemented interfaces no no
Initializes new instance fields yes no

You’ll need to patch your own version of java (latest as of today is 1.7.71)

This project is similar to JRebel. Main differences are:

  • HotswapAgent (DCEVM) supports Java8!
  • HotswapAgent does not need any additional configuration for basic project setup.
  • JRebel is currently more mature and contains more plugins.
  • JRebel is neither open source nor free.
  • JRebel modifies bytecode of all classes on reload. You need special IDE plugin to fix debugging.
  • HotswapAgent extraClasspath is similar to JRebel configuration
  • HotswapAgent adds watchResources configuration

Patching Java to use DCEVM

Download from https://github.com/dcevm/dcevm/releases the right patch for java 1.7.71 it is https://github.com/dcevm/dcevm/releases/download/light-jdk7u71%2B2/installer-light-jdk7u71.2.jar

Run it as administrator, it will find your installed Java JDK or you can use “Add installation directory”

Click on both Replace by DCEVM and Install DCEVM as altjvm

Now add to all  your launchers the following -XXaltjvm=dcevm

Reloading Spring Bean

Each application framework (Spring, Hibernate, Logback, …) needs special reloading mechanism to keep up-to-date after class redefinition (e.g. Hibernate configuration reload after new entity class is introduced). Hotswap agent works as a plugin system and ships preconfigured with all major framework plugins. It is easy to write your custom plugin even as part of your application.

Download agent.jar from https://github.com/HotswapProjects/HotswapAgent/releases

Save anywhere on disk, e.g. in C:\java\hotswap-agent.jar for example

add to all  your launchers the following -javaagent:C:\java\hotswap-agent.jar

Spring plugin uses agent services to:

  • Modify root Spring classes to get Spring contexts and registered scan path
  • Watch for any resource change on a scan path
  • Watch for a hotswap of a class file within a scan path package
  • Reload bean definition after a change
  • … and many other

References

About The Author

I worked with various Insurances companies across Switzerland on online applications handling billion premium volumes. I love to continuously spark my creativity in many different and challenging open-source projects fueled by my great passion for innovation and blockchain technology.In my technical role as a senior software engineer and Blockchain consultant, I help to define and implement innovative solutions in the scope of both blockchain and traditional products, solutions, and services. I can support the full spectrum of software development activities, starting from analyzing ideas and business cases and up to the production deployment of the solutions.I'm the Founder and CEO of Disruptr GmbH.

Categories