HotswapProjects / HotswapAgent

Java unlimited redefinition of classes at runtime.
GNU General Public License v2.0
2.29k stars 488 forks source link

Unable to add an extraClasspath using hotswap-agent.properties #398

Open Si-So opened 3 years ago

Si-So commented 3 years ago

Hi,

I want to add an extraClasspath by placing a hotswap-agent.properties into my classes-folder.

Here's my setup:

The hotswap-agent.properties only contains the following line:

extraClasspath=C:\\HIS-Workspace\\Tomcat\\tomcat-head_hot-swap\\eclipse-workspace\\cs.psv.account.generator\\bin;

When the hotswap-agent.properties is present, I get the following exception:

Caused by: java.lang.IllegalAccessError: superclass access check failed: class 
org.hotswap.agent.javassist.util.proxy.jdk_internal_loader_URLClassPath_$$_jvstab7_0 (in unnamed module @0x36bc55de) cannot access class jdk.internal.loader.URLClassPath (in module java.base) because module java.base does not export jdk.internal.loader to unnamed module @0x36bc55de

When deleting the hotswap-agent.properties and adding the following vm-argument, I do not get the exception:

-Dextra.class.path="C:/HIS-Workspace/Tomcat/tomcat-head_hot-swap/eclipse-workspace/cs.psv.account.generator/bin" 

After reading this stack overflow question https://stackoverflow.com/questions/43463251/java-illegalaccessorerror-superclass-access-check-failed, I suspect that this error may be caused by the requirement of our webapp to run on Java 11...

I have also tried starting with the following modification of my hotswap-agent.properties

extraClasspath=C:\HIS-Workspace\Tomcat\tomcat-head_hot-swap\eclipse-workspace\cs.psv.account.generator\bin;

This created the following exception:

HOTSWAP AGENT: 17:03:31.798 ERROR (org.hotswap.agent.config.PluginConfiguration) - Invalid configuration value: 'C:HIS-WorkspaceTomcatomcat-head_hot-swapeclipse-workspacecs.psv.account.generatorbin' is not a valid URL or path and will be skipped.

How do I specifiy extra classpathes in the hotswap-agent.properties without causing exceptions?

skybber commented 3 years ago

Did you try -XX:HotswapAgent=external ? This option opens modules for internal HA, there is doc for it on https://github.com/TravaOpenJDK/trava-jdk-11-dcevm.

Si-So commented 3 years ago

Hi,

Thanks for the fast reply.

These are now my VM arguments:

-XX:HotswapAgent=external
-javaagent:"C:/HIS-Workspace/Programme/dcevm-11.0.11+1/lib/hotswap/hotswap-agent.jar=disablePlugin=Hibernate"

This is the content of my hotswap-agent.properties

extraClasspath=C:/HIS-Workspace/Tomcat/tomcat-head_hot-swap/eclipse-workspace/cs.psv.account.generator/bin;
LOGGER=info
LOGFILE=C:/HIS-Workspace/agent.log

This is the content of the agent.log:

HOTSWAP AGENT: 10:13:21.089 INFO (org.hotswap.agent.plugin.spring.SpringPlugin) - Registering basePackage de.his.appserver.service.impl.cm.stu.reqmanagement
HOTSWAP AGENT: 10:13:21.093 INFO (org.hotswap.agent.watch.nio.TreeWatcherNIO) - Registering directory C:\HIS-Workspace\Tomcat\tomcat-head_hot-swap\webapps\qisserver\WEB-INF\classes\de\his\appserver\service\impl\cm\stu\reqmanagement 
HOTSWAP AGENT: 10:13:21.093 INFO (org.hotswap.agent.watch.nio.TreeWatcherNIO) - Registering directory C:\HIS-Workspace\Tomcat\tomcat-head_hot-swap\webapps\qisserver\WEB-INF\classes\de\his\appserver\service\impl\cm\stu\reqmanagement 
HOTSWAP AGENT: 10:13:42.290 INFO (org.hotswap.agent.plugin.myfaces.MyFacesPlugin) - MyFaces plugin initialized.
HOTSWAP AGENT: 10:13:42.293 INFO (org.hotswap.agent.watch.nio.TreeWatcherNIO) - Registering directory C:\HIS-Workspace\Tomcat\tomcat-head_hot-swap\eclipse-workspace\cs.psv.account.generator\bin 
HOTSWAP AGENT: 10:13:42.293 INFO (org.hotswap.agent.watch.nio.TreeWatcherNIO) - Registering directory C:\HIS-Workspace\Tomcat\tomcat-head_hot-swap\webapps\qisserver\WEB-INF\classes.instr 
HOTSWAP AGENT: 10:13:42.293 INFO (org.hotswap.agent.watch.nio.TreeWatcherNIO) - Registering directory C:\HIS-Workspace\Tomcat\tomcat-head_hot-swap\webapps\qisserver\WEB-INF\classes 
HOTSWAP AGENT: 10:13:42.310 INFO (org.hotswap.agent.watch.nio.TreeWatcherNIO) - Registering directory C:\HIS-Workspace\Tomcat\tomcat-head_hot-swap\lib 
HOTSWAP AGENT: 10:13:42.314 INFO (org.hotswap.agent.watch.nio.TreeWatcherNIO) - Registering directory C:\HIS-Workspace\Tomcat\tomcat-head_hot-swap\eclipse-workspace\cs.psv.account.generator\bin 
HOTSWAP AGENT: 10:13:42.315 INFO (org.hotswap.agent.watch.nio.TreeWatcherNIO) - Registering directory C:\HIS-Workspace\Tomcat\tomcat-head_hot-swap\webapps\qisserver\WEB-INF\classes.instr 
HOTSWAP AGENT: 10:13:42.315 INFO (org.hotswap.agent.watch.nio.TreeWatcherNIO) - Registering directory C:\HIS-Workspace\Tomcat\tomcat-head_hot-swap\webapps\qisserver\WEB-INF\classes 
HOTSWAP AGENT: 10:13:42.334 INFO (org.hotswap.agent.watch.nio.TreeWatcherNIO) - Registering directory C:\HIS-Workspace\Tomcat\tomcat-head_hot-swap\lib 
HOTSWAP AGENT: 10:13:42.335 INFO (org.hotswap.agent.config.PluginRegistry) - Plugin 'org.hotswap.agent.plugin.myfaces.MyFacesPlugin' initialized in ClassLoader 'ParallelWebappClassLoader
  context: qisserver
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@2fd1433e
'.
HOTSWAP AGENT: 10:13:46.532 INFO (org.hotswap.agent.plugin.myfaces.transformer.LifecycleImplTransformer) - Patching lifecycle implementation. classLoader: ParallelWebappClassLoader
  context: qisserver
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@2fd1433e

HOTSWAP AGENT: 10:13:46.533 INFO (org.hotswap.agent.plugin.myfaces.transformer.ManagedBeanResolverTransformer) - Patching managed bean resolver. Class loader: ParallelWebappClassLoader
  context: qisserver
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@2fd1433e

HOTSWAP AGENT: 10:13:46.702 INFO (org.hotswap.agent.plugin.myfaces.transformer.ManagedBeanResolverTransformer) - Patched managed bean resolver successfully.
HOTSWAP AGENT: 10:13:46.729 INFO (org.hotswap.agent.plugin.myfaces.transformer.LifecycleImplTransformer) - Patched lifecycle implementation successfully.
HOTSWAP AGENT: 10:13:47.268 INFO (org.hotswap.agent.config.PluginRegistry) - Plugin 'org.hotswap.agent.plugin.tomcat.TomcatPlugin' initialized in ClassLoader 'ParallelWebappClassLoader
  context: ROOT
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@2fd1433e
'.
HOTSWAP AGENT: 10:13:47.269 INFO (org.hotswap.agent.plugin.tomcat.TomcatPlugin) - Tomcat plugin initialized - Tomcat version '9.0.37.0'

Just by reading the agent.log, everything seems to be fine. However, now multiple spring beans cannot be initialized. The root cause is:

Caused by: java.lang.ClassNotFoundException

It seems to me that by adding the extraClasspath-line in hotswap-agent.properties, that (some) other pathes to classes/resource-files are now inaccessible.

I don't know if this is relevant, but I also observed another strange behavior:

When I remove =disablePlugin=Hibernate from my vm-argument and add the following line to my properties-file disabledPlugins=Hibernate, the Hibernate 5 plugin is loaded. Maybe this is worthy of another bug report?

skybber commented 2 years ago

Please, did you solve the problem?

Si-So commented 2 years ago

Unfortunately not.

skybber commented 2 years ago

As far as disabling Hibernate plugin, it works in my case. May be you see the hibernate plugin among Discovered plugins: when dcevm is starting. HA recognize all plugins on start and disablePlugin works later when your app is loaded, in case of Tomcat the disabled plugin should not be initialized in WebAppClassLoader.

ZLget commented 1 year ago

I had the same problem!

homejim commented 2 months ago

I encountered the same issue!

In my case, I was able to resolve the problem by including the following JVM option in the command line arguments when starting my Java application: --add-opens java.base/jdk.internal.loader=ALL-UNNAMED

This option instructs the JVM to open up the jdk.internal.loader package from the java.base module to all unnamed modules, effectively granting your application the necessary access to proceed without encountering an IllegalAccessError.

homejim commented 2 months ago

I encountered the same issue!

In my case, I was able to resolve the problem by including the following JVM option in the command line arguments when starting my Java application: --add-opens java.base/jdk.internal.loader=ALL-UNNAMED

This option instructs the JVM to open up the jdk.internal.loader package from the java.base module to all unnamed modules, effectively granting your application the necessary access to proceed without encountering an IllegalAccessError.

Due to the introduction of the module system in Java 9, there are stricter permissions in place for accessing internal packages. This is designed to enhance security and maintain better encapsulation within the Java platform

homejim commented 2 months ago

@skybber

skybber commented 2 months ago

I encountered the same issue! In my case, I was able to resolve the problem by including the following JVM option in the command line arguments when starting my Java application: --add-opens java.base/jdk.internal.loader=ALL-UNNAMED This option instructs the JVM to open up the jdk.internal.loader package from the java.base module to all unnamed modules, effectively granting your application the necessary access to proceed without encountering an IllegalAccessError.

Due to the introduction of the module system in Java 9, there are stricter permissions in place for accessing internal packages. This is designed to enhance security and maintain better encapsulation within the Java platform

It should work automatically if you use Trava11/JBR17/JBR21 + -XX:HotswapAgent=fatjar or -XX:HotswapAgent=core, what java distribution are you using?

homejim commented 2 months ago

I encountered the same issue! In my case, I was able to resolve the problem by including the following JVM option in the command line arguments when starting my Java application: --add-opens java.base/jdk.internal.loader=ALL-UNNAMED This option instructs the JVM to open up the jdk.internal.loader package from the java.base module to all unnamed modules, effectively granting your application the necessary access to proceed without encountering an IllegalAccessError.

Due to the introduction of the module system in Java 9, there are stricter permissions in place for accessing internal packages. This is designed to enhance security and maintain better encapsulation within the Java platform

It should work automatically if you use Trava11/JBR17/JBR21 + -XX:HotswapAgent=fatjar or -XX:HotswapAgent=core, what java distribution are you using?

Apologies, my previous statement was incorrect。Encountering this issue stems from directly adding the -javaagent:<path>/hotswap-agent.jar parameter to the JVM configuration and adding extraClasspath=target/extra to hotswap-agent.properties, without explicitly settingXX:HotswapAgent=external

image

After incorporating the -XX:HotswapAgent=external parameter, the agent runs smoothly. image

@skybber