Is there a way to check if a given jdk version is installed and registered ?

已回答

I'm trying to check if JDK version 1.8 is installed and is available in the project. I'm using the following snippet to get the list of jdk's installed. 

val projectJdkTable = ProjectJdkTable.getInstance()
val jdkType = JavaSdk.getInstance()
val jdkList: List<Sdk> = projectJdkTable.getSdksOfType(jdkType)

In the given jdk list I tried to check using `jdk.name` and `jdk.versionString` but in both string's I have no way to make sure that it's 1.8

In case of jdk.name: It is customisable by the user. any name can be specified. 

In case of jdk.version:

  • In mac I get version strings like `java version "1.8.0_77"
  • But in windows I got `java version "11.0.2"`

Is there any other way to extract the exact version of the JDK, other than the specified above version ?

0

Abhaydoshi7,

I'm not sure if I understood you correctly, but you have provided very different Java versions in the Mac/Windows cases, and I'm not sure what your problem is here.

Anyway, you can use JavaSdkVersion.fromVersionString method to parse the Java version name into enum variable, which will let you easily compare it is JDK_1_8 or not.

2

请先登录再写评论。