IDEA Tomcat HotSwap

Besides the posts about hot deploy on Tomcat Eclipse (WTP), and on JBoss exploded EAR/WAR, this is a similar post about Java hotswap based on the Java Platform Debugger Architecture (JPDA), or more specific layer, the Java Debug Wire Protocol (JDWP).

Yes, “hotswap” does not necessary mean to deploy, the Java app can see different results in runtime just via debugging. Okay later on you can still deploy to the web server so that it can run as production, but the point of hotswap is to speedup development process.

In this field, the leading software is JRebel, but its price is a bit high compared to living standards in developing countries in South East Asia, like Vietnam. Therefore I tried the “free” alternatives:
+ Dynamic Code Evolution (DCE) VM
+ HotswapAgent – a derivative work from DCEVM agent
+ SpringReloaded – also a similar approach to HotswapAgent (different bytecode lib)
+ Spring Boot DevTools – not really “hotswap” classes but “quick reload/restart”, and can “refresh” the static resources (CSS, HTML, …).

Anyway, they all are based on classloader replacement and bytecode instrumentation/manipulation.

In the end, I found that it’s still okay to use a “mix” of those, they are very close to JRebel if used properly.

For instance, I use DCEVM with SpringLoaded agent for general debug hotswapping, it’s good when using with servlet containers which takes time to restart/re-deploy, like Tomcat and JBoss web (the new “Undertow”). Jetty is still good and under-rated, as usual, but I will leave it as “low-profile” rather than being acquired and become bloated.

For general Java projects, I think HotSwapAgent provides good plug-ins for IDEs, though it’s still not popular on IntelliJ IDEA (yet).

I would recommend HotSwapAgent on IDEA users, but for local Tomcat debug I would use DCEVM with SpringLoaded:

VM Options: (either JAVA_OPTS / JPDA_OPTS / CATALINA_OPTS are all ok)

-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -javaagent:/home/ducquoc/.m2/repository/org/springframework/springloaded/1.2.7.RELEASE/springloaded-1.2.7.RELEASE.jar -noverify -XXaltjvm=dcevm

Spring Boot DevTools is on its way to become “hotswap”, for now it’s a quick reload/restart and can still be used with standard JVM debug hotswap (JDWP), thus it’s still better than “nothing”, and it has potential since Spring Boot is getting popular and can actually save the time/day rather than being “intrusive” like the old SpringFramework approach.


That’s it. The slow deployment time was a counter-productive factor of Java development, but things are much better now thanks to such debugging tools.




A coder, husband and brother...
This entry was posted in Coding, Linux. Bookmark the permalink.

One Response to IDEA Tomcat HotSwap

  1. Bonus: For IDE you may want to enable auto import Maven/Gradle changes (so that after updating Git repos the dependencies will be update automatically). For example IntelliJ IDEA can enable Auto Maven Imports at:

    File -> Settings -> Build, Execution, Deployment > Build Tools > Maven > Importing

    (old versions of IntelliJ IDEA:

    File -> Settings -> Maven > Importing


    Also, enable Annotation Processing will be good when you are using libraries such as Lombok or Mapstruct.

    File -> Settings -> Build, Execution, Deployment > Compiler > Annotation Processors

    (IntelliJ wrap line at 120 spaces:
    + format: Settings / … / Code Style / JAVA / Wrapping and Braces / Ensure right margin is not exceeded = Yes

    + typing: Settings / … / Code Style / JAVA / Wrapping and Braces / Wrap on typing = Yes


    (from: )

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s