简体   繁体   中英

Find whether the JDK is openJDK or Oracle JDK

I am building a application where user can change the Java setting and can point to any jdk. However it must be Oracle JDK and shouldn't be a openJDK. Is there any way to check whether the JDK is open JDK or Oracle JDK given its java path c:\\bin\\jdk\\binjava.exe ?

The easiest way would be to System.exec()

c:\bin\jdk\bin\java.exe -version

and parse it's output. OpenJDK and Sun JDK have different text outputs.

This is not optimal, but consider: Even if you find a difference in classname, functionality or similar, it would still only work for certain versions. You could never rely on a difference staying different.

java -version

Command will give Java Version details and Runtime environment name in its output text. Using the Runtime environment name you can find it out.

For example, if it is OpenJDK

openjdk version "<version>"
OpenJDK Runtime Environment .....
OpenJDK XX-Bit Server VM .....

For other JDK, you will see the JDK type in the output.

Sample:
    java version "<version>"
    Java(TM) SE Runtime Environment .....
    Java HotSpot(TM) XX-Bit Server VM .....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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