简体   繁体   中英

How to hotswap Java classes on a Tomcat outside the IDE with dcevm+hotswapagent

I'm trying to set up java class hot swapping on a Tomcat that is on my machine, but not configured in my IDE (Eclipse). In all the examples I can find the Tomcat server runs from within Eclipse. Is it possible to have code hot swapping with DCEVM+HotSwapAgent on an external tomcat? Here's what I've done so far:

  1. Set up DCEVM as the altjvm for jdk1.8.0_112 using DCEVM-light-8u112-installer.jar
  2. Updated the Tomcat's startup to include this: set JAVA_OPTS=-XXaltjvm=dcevm -javaagent:<path-to>hotswap-agent-1.0.jar %JAVA_OPTS%
  3. Deployed my application war which includes a hotswap-agent.properties in WEB-INF/classes

In my hotswap-agent.properties file, I've set the extraClasspath property to my project's bin folder in my eclipse workspace. I've also set autoHotswap=true (I'd like to have code hotswap whether or not the debugger is attached).

With this setup, I cannot get Tomcat to react to changes when I build in eclipse (it's set to build automatically). Am I missing something to get this to work?

Side note - I've done essentially the exact same thing as above with JRebel, so I know it's at least possible. I'm just trying to see if I can get this to work with all open source tools. Thanks in advance!

this is possible. Please check that you have extraClasspath set correctly - compile a file (check that new version of .class file is created on extraClasspath) and restart tomcat wihtout deployment of new WAR. If the change is not applied, then extraClasspath is not set correctly.

DEBUG level should also provide more details on rousources - there should be a line similar to Registering resource listener on classpath URI {}

Please download current HA release.

You can create a file for your context under conf/Catalina/localhost and make Tomcat reload your classes as you change them with Eclipse Build Automatically.

For Tomcat 8.5, your_project.xml file will look like, for other versions of Tomcat check the documentation as it may be slightly different.

<Context docBase="/eclipse-workspace/your_project/src/main/webapp">
<Resources>
    <PostResources className="org.apache.catalina.webresources.DirResourceSet"
                   base="/eclipse-workspace/your_project/target/classes" internalPath="/" webAppMount="/WEB-INF/classes" />
    <PostResources className="org.apache.catalina.webresources.DirResourceSet"
                   base="/eclipse-workspace/your_other_project/target/classes" internalPath="/" webAppMount="/WEB-INF/classes" />
    <PostResources className="org.apache.catalina.webresources.DirResourceSet"
                   base="/eclipse-workspace/your_external_libs" internalPath="/" webAppMount="/WEB-INF/lib" />
  </Resources>
</Context>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM