如何将/usr/libexec/java_home指向自定义jdk安装?
我在 macOS monterrey 上使用自定义 JDK 15(我必须使用为我的公司修改的自定义 JDK)。当我运行 /usr/libexec/java_home
时,出现此错误:
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.
但是,当我运行 echo $JAVA_HOME
时,出现 /Library/Java/JavaVirtualMachines/openjdk_15.0.6 _15.38.18_x64
。此外,运行 java --version 会返回正确的 JDK 版本。
因为/usr/libexec/java_home
没有指向实际的JDK目录,所以使用Java的工具不起作用。
有没有办法将 /usr/libexec/java_home
设置为指向我的 JDK 目录?
I'm on macOS monterrey and using a custom JDK 15 (I have to use a custom JDK modified for my company). When I run /usr/libexec/java_home
I get this error:
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.
however when I run echo $JAVA_HOME
I get /Library/Java/JavaVirtualMachines/openjdk_15.0.6_15.38.18_x64
. In addition running java --version
return the correct JDK version.
Because /usr/libexec/java_home
doesn't point to the actual JDK directory tools which use Java don't work.
Is there a way to set /usr/libexec/java_home
to point to my JDK directory?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
c4augustus 使用的简短答案几乎对我有用。令人不安的部分是找出链接目录的正确内容 - 如另一个答案,
/usr/libexec中找到的/java_home
搜索位于Contents/
目录下的Info.plist
文件。它位于由 Homebrew 安装在系统中的 OpenJDK 结构(在我的例子中)的更深处。简单地重新链接到正确的目录就可以了:
sudo ln -s /usr/local/Cellar/openjdk/18.0.1.1/libexec/openjdk.jdk/ /Library/Java/JavaVirtualMachines/openjdk-18.jdk< /code>
希望这对某人有帮助(我需要它来让 VS Code 能够处理 AsciiDoc 文档中的 PlantUML 图片)。
What c4augustus uses as a short answer almost worked for me. Uneasy part was figuring out the proper content of the linked directory – as found in another answer,
/usr/libexec/java_home
searches forInfo.plist
file located underContents/
dir.And that is located in greater depth of OpenJDK structure (in my case) installed in the system by Homebrew. Simple re-linking to proper directory made the trick:
sudo ln -s /usr/local/Cellar/openjdk/18.0.1.1/libexec/openjdk.jdk/ /Library/Java/JavaVirtualMachines/openjdk-18.jdk
Hope this helps someone (I needed it for VS Code being able to handle PlantUML pictures inside AsciiDoc documents). ????
请参阅以下问题以深入了解此主题:
如何更改从 /usr/libexec/java_home 返回的 Mac 操作系统默认 Java VM
如何设置或更改默认的 Java (JDK ) macOS 上的版本?
这是一个有效的简短答案:
在我的例子中,它指向最新 Android Studio 中的 JVM:
See these questions for a deep dive into this topic:
How can I change Mac OS's default Java VM returned from /usr/libexec/java_home
How to set or change the default Java (JDK) version on macOS?
Here is a short answer that works:
In my case, it points to the JVM in the latest Android Studio: