📜 ⬆️ ⬇️

Practical experience using this HotSwap

When we program, debug the code, look for the notorious "bug", often there is a situation when you have to restart the application server to see our changes. This leads to the fact that we have to get out of the "stream", to destroy our fragile sand castle of neural connections. Distract from the current task and wait, wait, wait, when our changes will be available on the application server. Sometimes it is so tiring ... It would be great to make a “hot” replacement for the changed classes and immediately see the result.

image

Many of us are aware of the existence of the Java HotSpot VM Swap mechanism, which allows you to make a "hot" replacement and avoid restarting the entire application server.

image
')
In IntelliJ IDEA, you can use the shortcut (: Command + Shift + F9 /: Ctrl + Shift + F9)

Due to existing limitations of Java HotSpot, it allows you to do this only to change the body of the existing class methods. In other cases, the modified classes will not be updated during the "hot swap".

image

In order to overcome this limitation, you can use the Dynamic Code Evolution Virtual Machine ( DCEVM ) - a modification of the Java HotSpot (TM) VM, which allows you to make an unlimited number of “hot” class replacements in real-time mode.

Sometimes simply replacing classes is not enough, especially when using different frameworks, for example, Spring . In such cases, it is necessary to take into account the "life cycle" of a framework. To solve this problem, you can use the HotSwapAgent special agent with DCEVM , which enhances the hot-swap capabilities and simplifies integration with your favorite IDE.

To integrate with IntelliJ IDEA:

1. Install the special HotSwapAgent plugin .

image

2. Set the "Reload classes after compilation: Always" configuration in IntelliJ IDEA in the HotSwap section.

image

3. The plugin allows you to activate HotSwapAgent agent for the entire project or for a specific configuration.

image

4. If the configuration is successful, the message “HOTSWAP AGENT” will be displayed on the console at startup.

image

5. To “hot swap” it is necessary to compile the modified classes, for this use the key combination (: Command + Shift + F9 /: Ctrl + Shift + F9).

Some examples for visual presentation:

Scenario 1: Modifying the body of a class method.

image

Scenario 2: Adding a method inside the class, changing the controller.

image

Enjoy your hot development!

References:
HotSwap plugin for IntelliJ IDEA , HotSwapAgent project , DCEVM

Source: https://habr.com/ru/post/325700/


All Articles