Search code examples
javaversion

Java System.getProperty("java.runtime.version") not reporting correctly


I am running a program using:

 System.out.println("Java Virtual Machine implementation version : " + 
         System.getProperty("java.vm.version"));
 System.out.println("Java runtime version: " +  
         System.getProperty("java.runtime.version" ));

This is compiled using java 11.0.12+7. I am running it with JDK oracle64-1.8.0.192:

PWRMacbookPro:~ username$ java -version
java version "1.8.0_192"
Java(TM) SE Runtime Environment (build 1.8.0_192-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.192-b12, mixed mode)
PWRMacbookPro:~ username$ 

First I would expect program compiled with a later version... But instead, I get:

Java Virtual Machine implementation version : 11.0.12+7
Java runtime version: 11.0.12+7

I must have my java environment screwed up? I am running mac os x and using jenv to switch between different versions of java. This all worked before installing Azul 11.0.12+7. I uninstalled Azul and gone back to AdoptOpenJDK 11.0.12+7. What have I screwed up?

EDIT:

Now, I am very confused. I went back to before installing Azul and everything is the same. I Have a jar that I compiled with java 11. I now switch my running JVM to 1.8 and execute my jar. I would expect and thought I had in the past gotten, "jar is compiled using a later version of the JDK", or some such message. I don't, it runs perfectly. What am I missing?


Solution

  • I’ve been beating my brain on this and getting nowhere. I have two java programs I turned into .app bundles on my MAC OS X system. Today, I tried running an 11 version on my Windows 10 system with JDK 1.8. It failed as I thought it should. It dawned on me that on Windows, I execute them as jars. I tried the same on Mac OS X (ie run the jar). It failed. My launch script in my application bundle looks for the highest level JDK on the system, not the currently active JDK.

    I hate to admit how much time I spent on this.