Mac下安装eclipse提示 to use the "java" command-line tool you need to install a JDK.
eclipse 2020-09 要求jdk是11版本以上
本地已经下载openjdk并配置系统路径,java -version 运行一切正常。
MacBook-Pro:java ice$ java -version
openjdk version "15" 2020-09-15
OpenJDK Runtime Environment (build 15+36-1562)
OpenJDK 64-Bit Server VM (build 15+36-1562, mixed mode, sharing)
路径配置:
#JAVA
#export JAVA_HOME=`/usr/libexec/java_home -v 15`
export JAVA_HOME="$program_dir/jdk/Contents/Home"
但不管是eclipse还是eclipse installer 依然报错。
查原因:Mac下eclipse寻找jdk是用命令
MacBook-Pro:java ice$/usr/libexec/java_home -V
Unable to find any JVMs matching version "(null)".
Matching Java Virtual Machines (0):
Default Java Virtual Machines (0):
No Java runtime present, try --request to install.
而此命令寻找的java的安装目录在“/Library/Java/JavaVirtualMachines“。
所以只要更改jdk的安装目录值mac指定目录,删除路径配置即可解决。
MacBook-Pro:java ice$ sudo mv jdk-15.jdk /Library/Java/JavaVirtualMachines/
MacBook-Pro:java ice$ vi ~/.bash_profile
MacBook-Pro:java ice$ source ~/.bash_profile
MacBook-Pro:java ice$ java -version
openjdk version "15" 2020-09-15
OpenJDK Runtime Environment (build 15+36-1562)
OpenJDK 64-Bit Server VM (build 15+36-1562, mixed mode, sharing)
MacBook-Pro:java ice$ /usr/libexec/java_home -V
Matching Java Virtual Machines (1):
15, x86_64: "OpenJDK 15" /Library/Java/JavaVirtualMachines/jdk-15.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk-15.jdk/Contents/Home
/Library/Java/JavaVirtualMachines 可以安装多个版本的jdk,这时候需要切换
在~/.bash_profile 可以做如下配置
# 展示jdk列表
/usr/libexec/java_home -V
# 配置语句
export JAVA_HOME=`/usr/libexec/java_home -v <version>`
# 示例
export JAVA_HOME=`/usr/libexec/java_home -v 15`