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.

./.

Advertisements

About DucQuoc.wordpress.com

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

4 Responses 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: https://ducquoc.wordpress.com/2017/05/01/git-pull-all/ )

  2. I have a work-around to display IDEA license as “OpenSourceContributor” , available til 2100.

    Download: http://www.mediafire.com/file/4h08pji220pa268/IDEA_2100.zip
    Extract the file IDEA_2100.jar to some folder, for example your $HOME folder (windows: %UserProfile%) , if your username is “opensource” it will be:
    Linux: /home/opensource
    MacOS: /Users/opensource
    Windows 10: C:\Users\opensource

    Then edit your IDEA vmoptions file (menu Help or menu Configure -> Edit Custom VM Options) :
    adding 1 line at the end, using javaagent pointing to the JAR like below:

    -javaagent:/home/opensource/IDEA_2100.jar

    Save the file then, restart IDEA completely, and now you can edit your Activation info
    (Help -> Register.. -> Edit Activation Code), by using something similar to IDEA_2100.json file:

    {“licenseId”:”OpenSourceSoftware Jenkins 18283″,
    “licenseeName”:”OpenSourceContributor”,
    “assigneeName”:”JENKINS-18283″,
    “assigneeEmail”:”open.source.18283@yopmail.com”,
    “licenseRestriction”:”II DM AC RS0 WS DPN RC PS DC RM CL PC DB GO RD”,
    “checkConcurrentUse”:false,
    “products”:[
    {“code”:”II”,”paidUpTo”:”2099-12-31″},
    {“code”:”DM”,”paidUpTo”:”2099-12-31″},
    {“code”:”AC”,”paidUpTo”:”2099-12-31″},
    {“code”:”RS0″,”paidUpTo”:”2099-12-31″},
    {“code”:”WS”,”paidUpTo”:”2099-12-31″},
    {“code”:”DPN”,”paidUpTo”:”2099-12-31″},
    {“code”:”RC”,”paidUpTo”:”2099-12-31″},
    {“code”:”PS”,”paidUpTo”:”2099-12-31″},
    {“code”:”DC”,”paidUpTo”:”2099-12-31″},
    {“code”:”RM”,”paidUpTo”:”2099-12-31″},
    {“code”:”CL”,”paidUpTo”:”2099-12-31″},
    {“code”:”PC”,”paidUpTo”:”2099-12-31″},
    {“code”:”DB”,”paidUpTo”:”2099-12-31″},
    {“code”:”GO”,”paidUpTo”:”2099-12-31″},
    {“code”:”RD”,”paidUpTo”:”2099-12-31″}
    ],
    “hash”:”2911276/0″,
    “gracePeriodDays”:7,
    “autoProlongated”:false}

    Then save the change by clicking OK button.
    From now on, when IDEA starts you can see the license info in the Splash, and in this menu.
    This works for all JetBrain new releases, not only IntelliJ IDEA (II) , but other variants as well : PhpStorm (PS), PyCharm (PC), RubyMine (RM), GoLand (GO), …

    works for 2018.2.3

  3. Pingback: Baby FirstYear Milestones | DucQuoc's Blog

  4. Pingback: FirstYear Development Stages | DucQuoc's Blog

Leave a Reply

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

WordPress.com Logo

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

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s