Set proper path on Visual studio Code for Java on M1 MacBook Pro

Viewed 3776

so I recently got the m1 MacBook Pro and I was able to install home-brew and install java with it which installed Java-16. The problem I'm facing is how to configure java with Visual Studio Code on the m1 Mac. When I look for java installed location where java it gives me

/opt/homebrew/opt/openjdk/bin/java
/usr/bin/java

But when I put this as the path /opt/homebrew/opt/openjdk in Visual Studio Code, it doesn't recognize it and gives me no jdk installed on the machine. doing java --version gives me

openjdk 17 2021-09-14
OpenJDK Runtime Environment Homebrew (build 17+0)
OpenJDK 64-Bit Server VM Homebrew (build 17+0, mixed mode)

I'm confused how to configure this properly and how to find the actual path of java installed so I can configure it with Visual Studio Code.

1 Answers

Restart VS Code, open Command Palette and choose Java: Configure Java Runtime, then turn to Java Tooling Runtime, choose openjdk17 as JDK for Language Server. Don't forget to Reload window to make the change effective:

enter image description here

The above configuration will generate java.home in User Settings.json automatically like:

"java.home": "C:\\Users\\Administrator\\Downloads\\openjdk-17-ea+26_windows-x64_bin\\jdk-17",

Try this and see if it solves your question.

Related