Which JRE am I using?

后端 未结 9 1225
暗喜
暗喜 2020-12-02 16:29

There are two varieties of JRE available. Java VM: IBM vs. Sun.

Is there a way to know which JRE I am using through JavaScript or some Java issued command.

9条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-02 17:19

    In Linux:

    java -version
    

    In Windows:

    java.exe -version
    

    If you need more info about the JVM you can call the executable with the parameter -XshowSettings:properties. It will show a lot of System Properties. These properties can also be accessed by means of the static method System.getProperty(String) in a Java class. As example this is an excerpt of some of the properties that can be obtained:

    $ java -XshowSettings:properties -version
    [...]
    java.specification.version = 1.7
    java.vendor = Oracle Corporation
    java.vendor.url = http://java.oracle.com/
    java.vendor.url.bug = http://bugreport.sun.com/bugreport/
    java.version = 1.7.0_95
    [...]
    

    So if you need to access any of these properties from Java code you can use:

    System.getProperty("java.specification.version");
    System.getProperty("java.vendor");
    System.getProperty("java.vendor.url");
    System.getProperty("java.version");
    

    Take into account that sometimes the vendor is not exposed as clear as Oracle or IBM. For example,

    $ java version
    "1.6.0_22" Java(TM) SE Runtime Environment (build 1.6.0_22-b04) Java HotSpot(TM) Client VM (build 17.1-b03, mixed mode, sharing)
    

    HotSpot is what Oracle calls their implementation of the JVM. Check this list if the vendor does not seem to be shown with -version.

提交回复
热议问题