在Linux OS上,OpenJDK和Oracle JDK java变量返回相同的结果。如何检测运行Java是OpenJDK还是Orackle JDK?
代码:
System.out.println("java.vendor: " + System.getProperty("java.vendor"));
System.out.println("java.version: " + System.getProperty("java.version"));
System.out.println("java.vendor.url: " + System.getProperty("java.vendor.url"));
输出:
java.vendor: Oracle Corporation
java.version: 1.7.0_55
java.vendor.url: http://java.oracle.com/
两个JDK的java -version命令是:
java version "1.7.0_55"
OpenJDK Runtime Environment (rhel-2.4.7.1.el6_5-x86_64 u55-b13)
OpenJDK 64-Bit Server VM (build 24.51-b03, mixed mode)
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) Server VM (build 24.51-b03, mixed mode)
答案 0 :(得分:7)
尝试:
System.out.println(System.getProperty("java.vm.name"));