5

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.

Vibhore Sagar
  • 75
  • 2
  • 6

2 Answers2

2

Adding the following configuration to settings.json makes VS Code choose the correct Homebrew JDK for my Maven projects:

    "java.configuration.runtimes": [
    {
      "name": "JavaSE-17",
      "path": "/opt/homebrew/Cellar/openjdk@17/17.0.5/libexec/openjdk.jdk/Contents/Home",
    },
    {
      "name": "JavaSE-11",
      "path": "/opt/homebrew/Cellar/openjdk@11/11.0.17/libexec/openjdk.jdk/Contents/Home",
      "default": true
    }
  ]

Just make sure that the configuration matches the actual versions you have installed.

Nicola Musatti
  • 17,834
  • 2
  • 46
  • 55
0

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.

Molly Wang-MSFT
  • 7,943
  • 2
  • 9
  • 22
  • 3
    Hi, I am on the M1 macbook pro, not on a windows computer. I tried this same method on macOs, but it doesnt show me any jdk in Options but I can see that Java in installed when i do ```java --version```. – Vibhore Sagar Jun 15 '21 at 22:35
  • @VibhoreSagar. Refer this [answer](https://stackoverflow.com/questions/22842743/how-to-set-java-home-environment-variable-on-mac-os-x-10-9) to add `java_home` on your machine. then restart vscode and try again. – Molly Wang-MSFT Jun 16 '21 at 01:33
  • How do you open `Command Pallette`? – IgorGanapolsky May 25 '22 at 15:46