jenv 在 MacOS 上找不到通过 brew 安装的 java 17

Posted

技术标签:

【中文标题】jenv 在 MacOS 上找不到通过 brew 安装的 java 17【英文标题】:jenv can't find java 17 installed through the brew on MacOS 【发布时间】:2022-01-14 16:34:33 【问题描述】:

我正在尝试使用 brew install openjdk@17 将 JDK 17 安装到 macOS BigSur (11.5.2)

> brew install openjdk@17
Running `brew update --preinstall`...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
Updated 3 formulae.

openjdk  is already installed but outdated (so it will be upgraded).
==> Downloading https://ghcr.io/v2/homebrew/core/openjdk/manifests/17.0.1_1
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/openjdk/blobs/sha256:75ee17c1331022fa8bf1e63f00fe903f23fe31d3a09021117d46b5f6ed1e26e1
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:75ee17c1331022fa8bf1e63f00fe903f23fe31d3a09021117d46b5f6ed1e26e1?se=2021-12-09T20%3A25%3A00Z&sig=NnB%2FO%2BGQF5ec6iqdKA4w29
######################################################################## 100.0%
==> Pouring openjdk--17.0.1_1.big_sur.bottle.tar.gz
==> Caveats
For the system Java wrappers to find this JDK, symlink it with
  sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk

openjdk is keg-only, which means it was not symlinked into /usr/local,
because macOS provides similar software and installing this software in
parallel can cause all kinds of trouble.

If you need to have openjdk first in your PATH, run:
  echo 'export PATH="/usr/local/opt/openjdk/bin:$PATH"' >> ~/.zshrc

For compilers to find openjdk you may need to set:
  export CPPFLAGS="-I/usr/local/opt/openjdk/include"

安装后jenv找不到java17的实例

jenv versions                                                                                                                               
  system
  1.8
  1.8.0.161
  1.8.0.181
* 11.0
  11.0.1
  15.0
  15.0.1
  openjdk64-11.0.1
  openjdk64-15.0.1
  oracle64-1.8.0.161
  oracle64-1.8.0.181

【问题讨论】:

【参考方案1】:

发现需要在jenv中使用命令注册java-17 dist:

jenv add /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home

/usr/local/opt/openjdk/libexec/openjdk.jdk 的路径您可以从 brew 安装日志中获取(在行 sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk ... 上找到)并添加 /Contents/Home

现在可以了

> jenv local 17.0
> java -version                                                                                                                                     
openjdk version "17.0.1" 2021-10-19
OpenJDK Runtime Environment Homebrew (build 17.0.1+1)
OpenJDK 64-Bit Server VM Homebrew (build 17.0.1+1, mixed mode, sharing)

【讨论】:

以上是关于jenv 在 MacOS 上找不到通过 brew 安装的 java 17的主要内容,如果未能解决你的问题,请参考以下文章

CMake 在 macOS 上找不到 libevent

在 macOS 11.3 上找不到“gl.h”

在 MacOS Sierra 上找不到 OpenSSL

为啥 jenv 中选择的 java 版本 8 实际上不是我 Mac 上的当前 java?

在 MacOs Mojave 上找不到 XAMPP 的 httpd-xampp.conf 文件

MySQL brew 无法在 macOS Monterey 上运行?