Hotswapping Java code

Hotswapping Java code is a technique that can save a lot of downtime for programmers when they are working with web applications that take forever to start up. Recompiling and reloading the changed classes allows you to see the effect of code changes while the application remains up and running.

The Java Virtual Machine supports hotswapping out of the box, but in a very rudimentary way. The capabilities of your standard JVM are limited to being able to hotswap the code for a method body. If you add, remove or rename methods, change their arguments, or make other changes to your code, you will need to restart.

The best-known tool for reloading code changes instantly is probably JRebel. It works great, and there is no doubt that this is a very useful weapon in the Java developer’s arsenal. But it is not free. If you can accept some minor restrictions, DCEVM is a very good alternative.

Here I will explain how easy it is to install DCEVM on Ubuntu and use it in Eclipse. Install it via apt:

sudo apt install openjdk-11-jre-dcevm

Add 

-dcevm 

to the VM arguments (Servers -> open launch configuration -> (Tab) Arguments -> VM arguments), and you are good to go.

 

Are you looking for a freelance Magnolia CMS developer? Feel free to contact me.