Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metals unable to find Java 11 JDK #2020

Closed
PawanKartikS opened this issue Aug 23, 2020 · 11 comments
Closed

Metals unable to find Java 11 JDK #2020

PawanKartikS opened this issue Aug 23, 2020 · 11 comments
Milestone

Comments

@PawanKartikS
Copy link

I've just installed the metals extension from VSCode's marketplace and opened a scala file. I immediately got this error -

Error: No suitable Java version found
Unable to find a Java 8 or Java 11 installation on this computer. To fix this problem, update the 'Java Home' setting to point to a Java 8 or Java 11 home directory or select a version to install automatically

I had JDK 14 installed but since metals explicitly mentioned JDK 11, I did go ahead and install it and configured the java.home property as

"java.home": "/usr/lib/jvm/java-11-openjdk-11.0.8.10-2.fc32.x86_64/"

which is in fact the correct path. Yet, the error persists.

OS: Fedora 32

@tgodzik
Copy link
Contributor

tgodzik commented Aug 24, 2020

Thanks for reporting! We do use an utility library for locating java home, but it might not work with all possible configuration unfortunately.

Could you try specifying java home in the settings? The exact settings is "metals.javaHome" : "path-to-home"

Also, are there any other messages in the metals output? There might be some more info there saying what else could be an issue.

@PawanKartikS
Copy link
Author

PawanKartikS commented Aug 24, 2020

That fixes it. I'm so sorry, not sure how I missed that configuration! Thanks!

@tgodzik
Copy link
Contributor

tgodzik commented Aug 24, 2020

Glad it helped! This probably means the message is not clear enough.

@tgodzik tgodzik closed this as completed Aug 24, 2020
@tgodzik tgodzik added this to the Metals v0.9.4 milestone Sep 18, 2020
@bes1002t
Copy link

I tried different approaches and only the last one worked:

  1. $JAVA_HOME (Support variables when resolving values in settings microsoft/vscode#2809)
  2. /usr/bin/java (which is actually a symlink to /usr/bin/java -> /etc/alternatives/java -> /usr/lib/jvm/java-11-openjdk-11.0.9.11-0.fc31.x86_64/bin/java)
  3. /usr/lib/jvm/java-11-openjdk-11.0.9.11-0.fc31.x86_64/

Why is /usr/bin/java/ not working? Is vscode not able to dissolve symlinks?

@tgodzik
Copy link
Contributor

tgodzik commented Dec 21, 2020

I think /usr/bin/java is only a symlink to the java binary, not actual path to java home.

$JAVA_HOME should work, although VS Code will most of the time be started without the JAVA_HOME env variable. You would most likely need to to start it from terminal to have it defined.

@pfernandez
Copy link

pfernandez commented Aug 2, 2021

Glad it helped! This probably means the message is not clear enough.

I ran into the exact same confusion today: Saw the update the 'Java Home' setting, went to :CocConfig, typed ja... and chose java.config.

Since the warning message isn't clear enough, maybe consider simply looking for java.home when metals.javaHome is doesn't exist.

@tgodzik
Copy link
Contributor

tgodzik commented Aug 6, 2021

Good idea, changed it in scalameta/metals-vscode#644

@godenji
Copy link

godenji commented Aug 6, 2022

I think /usr/bin/java is only a symlink to the java binary, not actual path to java home.

No, in most linux distros you'll see as @bes1002t points out, something like:

/usr/bin/java -> /etc/alternatives/java -> /usr/lib/jvm/java-18-openjdk-18.0.1.1.2-1.rolling.fc36.x86_64

Seems that vs code doesn't resolve symlinks, so your only option is to hard code the path, which is unfortunate.

@tgodzik
Copy link
Contributor

tgodzik commented Aug 8, 2022

How would using /usr/bin/java work if it was a symlink to a directory? Or do you mean something else?

We could possibly try to resolve the symlink and go up the directories to infer real java home, which might work. Would you mind raising it in VS Code repository scalameta/metals-vscode ?

@godenji
Copy link

godenji commented Aug 8, 2022

How would using /usr/bin/java work if it was a symlink to a directory?

I was incorrect, it does of course link to the java binary.

If the path resolves to a file named "java", then yes, you could probably traverse up to find java home. That would be a nice set-it-and-forget-it option for Linux users.

@godenji
Copy link

godenji commented Aug 8, 2022

Would you mind raising it in VS Code repository scalameta/metals-vscode ?

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants