Avoid usage of jdk.jconsole module in Java 9+ #113
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello,
Since Java 9, there is a warning (illegal reflective access operation) when using the jdk.jconsole module which contains classes like
LocalVirtualMachine
that are used to list local VMs and attach to them. On later Java version (17?), accessing these classes makes jmxterm crash.I implemented a
Jdk9JavaProcessManager
which relies only on the public Attach API (which is actually whatLocalVirtualMachine
appears to use under the hood, see: https://github.com/openjdk/jdk/blob/jdk8-b120/jdk/src/share/classes/sun/tools/jconsole/LocalVirtualMachine.java#L123). So my code is voluntarily based on what goes on in LocalVirtualMachine (especially when listing VMs).I had to adapt
WeakCastUtils
to build themethodMap
using not thefrom
instance (which in Jdk9 case is an instance ofVirtualMachineImpl
which is not part of the public API) but using the "original" interface, i.e.VirtualMachine
. When this distinction is not needed, I just usefrom.getClass()
.The source and target version remain Java 8.
Also, as the mininum Java version is 8, I'm not sure it's useful to keep
Jdk5JavaProcessManager
.If
WeakCastUtils
doesn't serve any other purpose than supporting multiple Java version, probably it could be replaced with Java 9 multi-release JARs: https://nipafx.dev/multi-release-jars-multiple-java-versions/.Note 1: this PR includes my other PR (#112).
Note 2: as I answered in #48, making jmxterm work with Java 17+ can be done by allowing access to the jdk.jconsole module (with
--add-exports jdk.jconsole/...
) but this is not supported by Java 8 and cannot be used with the Java 9--release
option.Best,
nyg
Fixes #48
Fixes #87
EDIT: I tested in the following way: compiled and ran (running
jvms
andopen
) jmxterm with both JDK8 and JDK21, but always leaving the maven.compiler.source and target to 1.8.