Why does IntelliJ not accept /usr/local/opt/openjdk (installed by Brew) as a JDK?

Answered

In the "Setup JDK" dialog when I add a JDK and choose the path "/usr/local/opt/openjdk" (which is where brew installed openjdk). IntelliJ tells me “The selected directory points to a JRE not a JDK.”

Any idea why? I'm pretty sure I have a fully functional JDK.

3
12 comments

Does it have the standard JDK layout?

What's the output from /usr/local/opt/openjdk/bin/java -version command?

0

I'm not familiar enough with the JDK to know what the standard layout looks like. It does have a javac at the very least.

 

$ /usr/local/opt/openjdk/bin/java -version

OpenJDK 64-Bit Server VM (build 13.0.2+8, mixed mode, sharing)

0

Standard layout would have lib and jmods subdirectories, etc:

We may check what's wrong if you attach ls -lR output for the usr/local/opt/openjdk/ directory.

0

ls -lR is too long to list here (and if there's a way to attach files, I can't see it), but the directory contains:

INSTALL_RECEIPT.json
README
include
LICENSE
bin
libexec

Looks like it may not be a complete jdk, but it's totally bizarre to me why the Brew package is called openjdk, which purports to be a JDK.

I'll try with this "adoptopenjdk" thing. Thank you!

1

Look under libexec, brew usually installs the standard layout copy there.

3

Oh hey whaddya know, there is an openjdk.jdk dir there. Thanks!

How did you figure this out? I feel pretty silly that I had to ask on IntelliJ support of all places. I suppose I could have just looked at the recursive ls like you suggested....

0

I've answered similar questions about Groovy and Scala setup for brew:

https://stackoverflow.com/a/46125537/104891
https://stackoverflow.com/a/10828320/104891 .

Just assumed it's the same for OpenJDK.

0

Revisiting this issue. Homebrew puts the standard java layout here:

$ /opt/homebrew/opt/openjdk@11/libexec/openjdk.jdk/Contents/Home

$ ls

bin conf demo include jmods legal lib man release

I put that path as my $JAVA_HOME. The issue now is that I can't get IntelliJ to load a JDK from that path. I'm using a mac with OS Monterey. I ended up just using a symlink:

$ sudo ln -sfn /opt/homebrew/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk

Now, IntelliJ can find the JDK. Is there any conflict with my $JAVA_HOME now?

3

Eric Balawejder Could you please clarify your question? What's the specific issue you have now once you added JDK in IntelliJ IDEA? What conflict are you referring to?

0

I understand that the $JAVA_HOME path is used for the IDE and other tools such as maven. My $JAVA_HOME path points to the homebrew installation:

/opt/homebrew/opt/openjdk@11/libexec/openjdk.jdk/Contents/Home

There is a symlink from the homebrew path to /Library/Java/JavaVirtualMachines/openjdk-11.jdk so that IntelliJ could find the installation in the file selector. Will pointing my $JAVA_HOME path to the homebrew installation cause any issues with the IDE?

0

Gradle sync can fail if the paths differ, see https://stackoverflow.com/a/61806948/104891.

0

Thank you. Yes, I was able to reproduce that error when creating a new gradle project in IntelliJ. My new java home is JAVA_HOME=$(/usr/libexec/java_home -v 11) and this resolves that error.

0

Please sign in to leave a comment.