67934

How to find the JVM version from a program … with even more details?

Question:

I have read <a href="https://stackoverflow.com/questions/5103121/how-to-find-the-jvm-version-from-a-program" rel="nofollow">this</a>, but it <em>ain't good enough</em>!

What I mean is: when i run

<blockquote>

java -version

</blockquote>

I get:

java version "1.8.0" Java(TM) SE Runtime Environment (build pxa6480sr3fp20-20161019_02(SR3 FP20)) IBM J9 VM (build 2.8, JRE 1.8.0 Linux amd64-64 Compressed References 20161013_322271 (JIT enabled, AOT enabled) J9VM - R28_Java8_SR3_20161013_1635_B322271 JIT - tr.r14.java.green_20161011_125790 GC - R28_Java8_SR3_20161013_1635_B322271_CMPRSS

...

But when I use any of the programmatic ways to access the JVM version "from within" (as outlined by the question I am linking to), I only see values such as:

Property: java.vm.specification.version : 1.8 Property: java.vm.specification.vendor : Oracle Corporation Property: java.vm.specification.name : Java Virtual Machine Specification Property: java.vm.version : 2.8 Property: java.vm.vendor : IBM Corporation Property: java.vm.name : IBM J9 VM Property: java.specification.version : 1.8 Property: java.specification.vendor : Oracle Corporation Property: java.specification.name : Java Platform API Specification

Using

MX bean --- vmversion: 2.8

My problem: our build server runs a slightly <em>older</em> version of IBM java. java -version would show that, like

J9VM - R28_Java8_SR1_20150410_1531_B243669

But: when I print those system properties, such details are lost! I have not found a way to write java code that would be able to distinguish that slightly older JVM from the newer one.

Long story short: is there any programmatic way to do something "within my JVM" that would give me that level of detail?

(basically I need that to dynamically disable some of our JUnit tests; they simply dont work with the older JVM; but I want them to be executed when running in my local eclipse installation with a newer JVM)

Answer1:

I don't have IBM Java, only Oracle Java. When I do java -version I get:

<pre class="lang-none prettyprint-override">java version "1.8.0_91" Java(TM) SE Runtime Environment (build 1.8.0_91-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

I can reproduce that exact output with this code:

System.out.printf("java version \"%s\"%n" + "%s (build %s)%n" + "%s (build %s, %s)%n", System.getProperty("java.version"), System.getProperty("java.runtime.name"), System.getProperty("java.runtime.version"), System.getProperty("java.vm.name"), System.getProperty("java.vm.version"), System.getProperty("java.vm.info"));

There might be other information added by IBM Java. Why not try dumping all system properties and see for yourself:

new TreeMap<>(System.getProperties()).entrySet().forEach(e -> System.out.printf("%s = %s%n", e.getKey(), e.getValue()) );

Recommend

  • GCC vs Microsoft : Undefined reference to `_chkstk'?
  • Index on every Foreign Key?
  • Hide JetBrains annotation on popup JavaDoc in IntelliJ
  • Make background for table rows extend past the bounds of the table
  • Why == is different for Integer and String?
  • Using LINQ with IBM i
  • Issue with std::thread when using g++ in 32-bit MinGW 4.8.0
  • Unable to use dot layout (graphviz as a library)
  • Selenium - How to skip the record from the Set after the its first occurrence
  • Getting zero results in search using elastic4s
  • RPMs for IDAS IoTAgents GE, from Fiware
  • Run script file on remote server
  • Find VMID for running instance
  • Separate ID and Class for JS and CSS
  • Feature detection of foreignObject in SVG
  • Why does the font in these TD elements render at different sizes?
  • garbled css name when styling within UiBinder
  • How to open html table in xls on click of a button
  • What is the correct way to synchronize a shared, static object in Java?
  • Database structure design with variable amounts of fields
  • Read a local file using javascript
  • Ajax Loaded meta Tags
  • Xamarin Forms - UWP Fonts
  • Pass value from viewmodel to script in zk
  • How do I fake an specific browser client when using Java's Net library?
  • How to get a value (ex: baseURL) in every Karate feature?
  • Arrow is showed instead of the material design version hamburger icon. Why doesn't syncState in
  • Convert array of 8 bytes to signed long in C++
  • Apache 2.4 - remove | delete | uninstall
  • Unanticipated behavior
  • Arrays break string types in Julia
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • Unit Testing MVC Web Application in Visual Studio and Problem with QTAgent
  • Benchmarking RAM performance - UWP and C#
  • Error creating VM instance in Google Compute Engine
  • Understanding cpu registers
  • Are Kotlin's Float, Int etc optimised to built-in types in the JVM? [duplicate]
  • Checking variable from a different class in C#
  • Recursive/Hierarchical Query Using Postgres
  • Running Map reduces the dimensions of the matrices