Using hotswapAgent with Tomcat

1,018 views
Skip to first unread message

Mark Gordon

unread,
Mar 15, 2017, 4:41:16 PM3/15/17
to HotswapAgent
I am using Tomcat 8 with jdk 1.8.0_112.

I am using the latest hotswapAgent.  Patched my JDK.

I see the hotswap messages in the log files.

I make a small change to a class.  Recompile but don't see the change when I use the class from a JSP page.  Real simple test case.

I am a user of JRebel and I am using hotswap agent as I did in jrebel with the same setup.  Am I missing something? 

Thanks
Mark

HOTSWAP AGENT: 13:38:16.862 INFO (org.hotswap.agent.config.PluginRegistry) - Plugin 'org.hotswap.agent.plugin.tomcat.TomcatPlugin' initialized in ClassLoader 'ParallelWebappClassLoader
  context: solr
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@1f28c152
'.
HOTSWAP AGENT: 13:38:16.862 INFO (org.hotswap.agent.plugin.tomcat.TomcatPlugin) - Tomcat plugin initialized - Tomcat version '8.5.9.0'

vladimir dvorak

unread,
Mar 16, 2017, 2:55:58 AM3/16/17
to HotswapAgent
Check if our class was depoyed to Tomcat, then look at messages related to JSP here and issues on HA's github repo.

Mark Gordon

unread,
Mar 27, 2017, 1:54:53 PM3/27/17
to HotswapAgent
The class file was deployed to my webapp's WEB-INF/classes folder  It does not seem to see the change and is not reloading.

Does this not work with JSP pages?  Tomcat is attempting to recompile the jsp and it is not seeing the new method added to the class.

I must have something not set up correctly.  This is about as simple of a test as you could have with tomcat.

I read something about debug mode?  Is the reload service turned off by default.  Do I need to somehow turn it on?

Thanks,
-Mark

vladimir dvorak

unread,
Mar 27, 2017, 4:48:26 PM3/27/17
to HotswapAgent
If the class is not redefined in JVM then you are either not using debugger or you missed configure Auto Hotswap. We have solved a similar problem with JSP recently. I would recommend you to look at the sample project from this issue.

Mark Gordon

unread,
Mar 27, 2017, 5:00:03 PM3/27/17
to HotswapAgent
So you have to start tomcat with debug?  I have never done this.  So yeah I am not using the debugger.

When I try to start tomcat with debug I get this error (catalina.sh debug) :
invalid option: -javaagent:/u/mark/Downloads/hotswap-agent-1.1.0-SNAPSHOT.jar

That option works when using catalina.sh run

vladimir dvorak

unread,
Mar 27, 2017, 5:28:01 PM3/27/17
to HotswapAgent
-javaagent:/u/mark/Downloads/hotswap-agent-1.1.0-SNAPSHOT.jar  is JVM option. But you can use HA without debugger using autoHotswap=true - look at the project I've sent.


Mark Gordon

unread,
Mar 27, 2017, 5:34:05 PM3/27/17
to HotswapAgent
Thanks Vladimir,

I am making some progress!!!  I added autoHotSwap=true.
I made a small change to a method.  I changed the output in a System.out.println statement.

Now if I change a class and recompile the class I get this:

HOTSWAP AGENT: 14:31:31.969 RELOAD (org.hotswap.agent.config.PluginManager) - Reloading classes [com.sunbeltdcs.rules.ItemValue] (autoHotswap)
Exception in thread "Thread-1309" java.lang.IllegalStateException: Unable to redefine classes
at org.hotswap.agent.config.PluginManager.hotswap(PluginManager.java:272)
at org.hotswap.agent.plugin.hotswapper.HotswapperPlugin$1.executeCommand(HotswapperPlugin.java:94)
at org.hotswap.agent.command.impl.CommandExecutor.run(CommandExecutor.java:25)
Caused by: java.lang.UnsupportedOperationException: class redefinition failed: attempted to add a method
at sun.instrument.InstrumentationImpl.redefineClasses0(Native Method)
at sun.instrument.InstrumentationImpl.redefineClasses(InstrumentationImpl.java:170)
at org.hotswap.agent.config.PluginManager.hotswap(PluginManager.java:269)

Mark Gordon

unread,
Mar 27, 2017, 6:07:58 PM3/27/17
to HotswapAgent
I was able to get it to load a change to an existing method in a class.  It had to be a really simple class.  I had a class that extended another class and it could not reload that class, not sure if that was why.  It was a bigger class.

The real simple case of having a base class with one method.  I made a small change and it reloaded the change.  I added a new method and got the same error that adding a new method was unsupported.

Exception in thread "Thread-1365" java.lang.IllegalStateException: Unable to redefine classes
at org.hotswap.agent.config.PluginManager.hotswap(PluginManager.java:272)
at org.hotswap.agent.plugin.hotswapper.HotswapperPlugin$1.executeCommand(HotswapperPlugin.java:94)
at org.hotswap.agent.command.impl.CommandExecutor.run(CommandExecutor.java:25)
Caused by: java.lang.UnsupportedOperationException: class redefinition failed: attempted to add a method
at sun.instrument.InstrumentationImpl.redefineClasses0(Native Method)
Exception in thread "Thread-1364" at sun.instrument.InstrumentationImpl.redefineClasses(InstrumentationImpl.java:170)
at org.hotswap.agent.config.PluginManager.hotswap(PluginManager.java:269)
... 2 more
Exception in thread "Thread-1363" java.lang.IllegalStateException: Unable to redefine classes
at org.hotswap.agent.config.PluginManager.hotswap(PluginManager.java:272)
at org.hotswap.agent.plugin.hotswapper.HotswapperPlugin$1.executeCommand(HotswapperPlugin.java:94)
at org.hotswap.agent.command.impl.CommandExecutor.run(CommandExecutor.java:25)
Caused by: java.lang.UnsupportedOperationException: class redefinition failed: attempted to add a method
at sun.instrument.InstrumentationImpl.redefineClasses0(Native Method)
at sun.instrument.InstrumentationImpl.redefineClasses(InstrumentationImpl.java:170)
at org.hotswap.agent.config.PluginManager.hotswap(PluginManager.java:269)
... 2 more
java.lang.IllegalStateException: Unable to redefine classes
at org.hotswap.agent.config.PluginManager.hotswap(PluginManager.java:272)
at org.hotswap.agent.plugin.hotswapper.HotswapperPlugin$1.executeCommand(HotswapperPlugin.java:94)
at org.hotswap.agent.command.impl.CommandExecutor.run(CommandExecutor.java:25)
Caused by: java.lang.UnsupportedOperationException: class redefinition failed: attempted to add a method
at sun.instrument.InstrumentationImpl.redefineClasses0(Native Method)
at sun.instrument.InstrumentationImpl.redefineClasses(InstrumentationImpl.java:170)
at org.hotswap.agent.config.PluginManager.hotswap(PluginManager.java:269)
... 2 more

Jiří Bubník

unread,
Mar 28, 2017, 4:27:39 AM3/28/17
to Mark Gordon, HotswapAgent

Hi,

 

Caused by: java.lang.UnsupportedOperationException: class redefinition failed: attempted to add a method

 

You did not use DCEVM JVM (either patched java, or –altjvm switch).

 

Jiri

--
You received this message because you are subscribed to the Google Groups "HotswapAgent" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hotswapagent...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages