[英]Set proper path on Visual studio Code for Java on M1 MacBook Pro
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.所以我最近得到了 m1 MacBook Pro,我能够安装自制软件并安装 java,它安装了 Java-16。 The problem I'm facing is how to configure java with Visual Studio Code on the m1 Mac.
我面临的问题是如何在 m1 Mac 上使用 Visual Studio Code 配置 java。 When I look for java installed location
where java
it gives me当我寻找 java 安装位置
where java
它给了我
/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.但是当我将它作为路径
/opt/homebrew/opt/openjdk
放在 Visual Studio Code 中时,它无法识别它并且没有在机器上安装任何 jdk。 doing java --version
gives me做
java --version
给我
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.我很困惑如何正确配置它以及如何找到 java 安装的实际路径,以便我可以使用 Visual Studio Code 对其进行配置。
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.重启VS Code,打开Command Palette,选择Java:Configure Java Runtime ,然后转到Java Tooling Runtime ,选择openjdk17作为Language Server的JDK。 Don't forget to Reload window to make the change effective:
不要忘记重新加载 window以使更改生效:
The above configuration will generate java.home
in User Settings.json automatically like:上面的配置会在User Settings.json自动生成
java.home
像:
"java.home": "C:\\Users\\Administrator\\Downloads\\openjdk-17-ea+26_windows-x64_bin\\jdk-17",
Try this and see if it solves your question.试试这个,看看它是否能解决您的问题。
Adding the following configuration to settings.json
makes VS Code choose the correct Homebrew JDK for my Maven projects:将以下配置添加到
settings.json
使 VS Code 为我的 Maven 项目选择正确的 Homebrew JDK:
"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.只需确保配置与您安装的实际版本相匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.