Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij IDEA 2017.2 can't add openjk 9 on Linux Mint 18

I am using Intellij IDEA 2017.2.5 on Linux Mint 18.2 and trying to add new openjdk-9 SDK but IDEA does not accept openjdk 9 as valid JDK:

Intellij claims about SDK home

I have installed all of my SDKs using apt-get from ppa standard repositories.
This is my update-alternatives --config java/javac output:

update-alternatives --config java/javac

Although Intellij declared it would support JDK 9 here, but it seems it is not yet fully compatible with at least opensdk-9.
Maybe refactoring SDK directory and removing 'jre' folder misleads the IDEA to find the SDK 9 home folder.

Any idea why Intellij IDEA claims 'The selected directory is not a valid home for JDK' ?

like image 254
Kayvan Tehrani Avatar asked Nov 07 '22 16:11

Kayvan Tehrani


1 Answers

“ Ubuntu PPA for OpenJDK” currently has very old build of openjdk-9(9~b115-1ubuntu1).
So the IDEA does not recognize it as a valid SDK.
I removed current installed version:

sudo apt-get remove '^openjdk-9.*'

Then I have downloaded newer .deb build(9~b181) files including jre,jre-headless,... from launchpad build archive.

sudo dpkg -i openjdk-9-jre-headless_9_b181-4_amd64.deb  
             openjdk-9-jre_9_b181-4_amd64.deb 
             openjdk-9-jdk-headless_9_b181-4_amd64.deb 
             openjdk-9-jdk_9_b181-4_amd64.deb

Just Execute the above command at a single line, line breaks are for better readability.

Ignore any error complaining about:

"Package libpng16-16 is not installed."

Next execute the following:

  sudo apt-get install -f

Now after installing this build of openjdk-9 the IDEA is happy with SDK home.

Thanks @y.bedrov for his useful comment.

Update: However this solution enables you to declare openjdk-9 in the mentioned IDEA version(2017-2) but you are not able to compile any class within the IDEA itself. You can only compile your application with elder jdk and run it with openjdk-9. There is an other issue which indicates this here.

In the newer IDEA versions(I have tested 2017.3) this build of openjdk is not allowed to be used as new SDK any more, see this issue.

The short reason is an issue in Debian package which contains incorrectly compiled lib/jrt-fs.jar file.

See this Answer for more information

like image 63
Kayvan Tehrani Avatar answered Nov 15 '22 06:11

Kayvan Tehrani