Reputation: 6932
I'm looking to remotely determine the version of Java that a particular process is running on through JMX. Specifically, I would like something like "1.6.0_26", which is what System.getProperty("java.version")
would return.
Through the RunTime MBean, I can check the VmName and VmVersion attributes, which give "Java HotSpot(TM) 64-Bit Server VM" and "20.1-b02", respectively. I'm not sure where the "20.1-b02" comes from; is there a way to match that to the "1.6.0_26" version?
Upvotes: 1
Views: 2775
Reputation: 21
Turns out that older versions of the JVM / JMX return the wrong thing for specVersion, so using the technique that @Kent provided works much better:
getLogger().finest("Checking JVM version");
String specVersion = ManagementFactory.getRuntimeMXBean().getSpecVersion();
getLogger().log(Level.FINEST, "Specification Version from JMX = ''{0}''", specVersion);
// Because of bug in the above call, earlier versions of JMX reported the version of
// JMX and not Java (so 1.6 reports 1.0 - replacing with the call below fixes this problem
// and consistently returns the specification of the JVM that is being used.
String javaVersion = ManagementFactory.getRuntimeMXBean().getSystemProperties().get("java.specification.version");
getLogger().log(Level.FINEST, "java.specification.version found ''{0}''", javaVersion);
Upvotes: 0
Reputation: 23525
A number of hints for the java.lang.Runtime
bean:
java.runtime.version
Edit
As @Kent pointed out java.lang.management.RuntimeMXBean.getSystemProperties()
in code is the same as SystemProperties
-> java.runtime.version
in a JMX client like JConsole.
Upvotes: 4