简体   繁体   English

如何知道我使用的是 Open JDK 还是 Oracle JDK?

[英]How to know if I am using Open JDK or Oracle JDK?

Using java -version gives me this.使用 java -version 给了我这个。

java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)

Is it an OpenJDK or OracleJDK ?它是 OpenJDK 还是 OracleJDK ?

I think that you're using OracleJDK. 我认为你正在使用OracleJDK。

As I saw with a google search, the openJDK --version output is like this: 正如我在google搜索中看到的那样,openJDK --version输出如下:

java -version java -version

openjdk version "1.8.0-internal" openjdk版本“1.8.0-internal”

OpenJDK Runtime Environment (build 1.8.0-internal-0) OpenJDK运行时环境(build 1.8.0-internal-0)

OpenJDK 64-Bit Zero VM (build 25.0-b20-internal, interpreted mode) OpenJDK 64位零虚拟机(构建25.0-b20内部,解释模式)

See: http://mail.openjdk.java.net/pipermail/jdk8-dev/2013-July/002840.html 请参阅: http//mail.openjdk.java.net/pipermail/jdk8-dev/2013-July/002840.html

On debian, jessie-backports, openjdk-8: 关于debian,jessie-backports,openjdk-8:

openjdk version "1.8.0_66-internal"
OpenJDK Runtime Environment (build 1.8.0_66-internal-b17)
OpenJDK 64-Bit Server VM (build 25.66-b17, mixed mode)

Using the ubuntu ppa for oracle-java-8: 使用ubuntu ppa for oracle-java-8:

java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)

I would assume, the string "java" at the beginning denotes Oracle Java, whereas the OpenJDK gets you "openjdk". 我认为,开头的字符串“java”表示Oracle Java,而OpenJDK则为“openjdk”。

Call sun.misc.Version#println in java code will dump the version info to stderr. 在java代码中调用sun.misc.Version#println会将版本信息转储到stderr。 If you want to fetch the JDK version from java code. 如果要从java代码中获取JDK版本。

package bj.tmp;

import sun.misc.Version;

public class Foo {
    public static void main(String[] args) {
        Version.println();
    }
}

Like this: 像这样:

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)

Based on actual test I did on my system by using Oracle JDK and OpenJDK:根据我使用 Oracle JDK 和 OpenJDK 在我的系统上进行的实际测试:

Option 1选项1

  • You can execute the java –version command and in the case of OpenJDK you will clearly see “openjdk” in the output while in case of Oracle JDK you will se “Hotspot” in the output.您可以执行java –version命令,对于 OpenJDK,您将在输出中清楚地看到“openjdk”,而对于 Oracle JDK,您将在输出中看到“Hotspot”。 That's how you can differentiate.这样你就可以区分了。
  • Below is actual from my system:以下是我系统中的实际情况:

C:\Users\himanshu.agrawal>"C:\E_Drive\Softwares\OpenJDK-java-se-7u75-ri\jre\bin\java" -version
openjdk version "1.7.0_75"
OpenJDK Runtime Environment (build 1.7.0_75-b13)
OpenJDK Client VM (build 24.75-b04, mixed mode)

C:\Users\himanshu.agrawal>java -version
java version "1.8.0_301"
Java(TM) SE Runtime Environment (build 1.8.0_301-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.301-b09, mixed mode)

Option 2选项 2

  • You can use java.vm.name or java.runtime.name system property.您可以使用java.vm.namejava.runtime.name系统属性。
  • I think since Oracle is still the key contributor / responsible for the OpenJDK project so if you use java.vm.vendor or java.specification.vendor you still get Oracle as the vendor.我认为,由于 Oracle 仍然是 OpenJDK 项目的主要贡献者/负责人,因此如果您使用java.vm.vendorjava.specification.vendor ,您仍然可以将 Oracle 作为供应商。
  • Below actual output from my system for these properties:下面是我系统的这些属性的实际输出:

// when using OpenJDK
java.vm.name = OpenJDK 64-Bit Server VM
java.runtime.name = OpenJDK Runtime Environment
java.vm.vendor = "Oracle Corporation"
java.specification.vendor = Oracle Corporation

// when using Oracle JDK
java.vm.name = Java HotSpot(TM) 64-Bit Server VM
java.runtime.name = Java(TM) SE Runtime Environment
java.vm.vendor = Oracle Corporation
java.specification.vendor = Oracle Corporation

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM