7

Question: What system properties are set by OpenJDK's vm so that I can identify that I am running under OpenJDK and not under Sun/Oracle's vm?

As shown here: https://gist.github.com/sinewalker/3890869, the following system properties are NOT sufficient for differentiating between OpenJDK's VM and Sun/Oracle's VM:

System properties:

System.out.println(System.getProperty("java.vendor"));
System.out.println(System.getProperty("java.vendor.url"));
System.out.println(System.getProperty("java.version"));

Outputs the following using OpenJDK's vm (these are the same values you would see on Sun's VM):

Sun Microsystems Inc.
http://java.sun.com/
1.6.0_24

I was expecting the property values to reflect what is output by the java command:

$ java -version
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.4) (6b24-1.11.4-1ubuntu0.12.04.1)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)
Chris Snow
  • 23,813
  • 35
  • 144
  • 309
  • You can also print `System.out.println(System.getProperties());` to see all the available values. – assylias Aug 04 '13 at 20:18
  • Why do you need to know the difference? For any modern JVM, you shouldn't need to care about the differences between the two. – kittylyst Aug 05 '13 at 15:18
  • I have maven [build](http://stackoverflow.com/questions/18043083/is-sun-oracle-jdk-required-to-build-wso2-4-1-x) that only works with Oracle/Sun JDK. I am trying to use [maven-enforce-plugin](http://stackoverflow.com/questions/18045697/how-to-enforce-a-specific-jdk-vendor-as-a-pre-requisite-of-the-build) to detect if an invalid JDK is being used so the build can fail early. – Chris Snow Aug 05 '13 at 15:23
  • You cannot rely on strings meant for human consumption. Instead write a small java program testing if the JVM has the desired behavior. For modern JDK’s the `java Foo.java` automatic compilation may be convenient. – Thorbjørn Ravn Andersen Nov 22 '22 at 11:23

1 Answers1

5

Try using these:

System.out.println(System.getProperty("java.vm.version"));
System.out.println(System.getProperty("java.runtime.name"));
System.out.println(System.getProperty("java.vm.name"));

You might also like System#getProperties():

System.getProperties().list(System.out);

which will list all the current System properties, to System.out.

Rohit Jain
  • 209,639
  • 45
  • 409
  • 525
  • 1
    Thanks but java.vm.version is useless for this purpose unlike the 2 other properties, I've just tested with OpenJDK 1.7 update 55 under Mageia Linux 4 64 bits. – gouessej Jul 19 '14 at 11:29