gpt4 book ai didi

java - 为什么 command/usr/libexec/java_home 不起作用?

转载 作者:行者123 更新时间:2023-12-05 03:46:49 25 4
gpt4 key购买 nike

操作系统:MacOS Big Sur 11.0.1

我使用 /usr/libexec/java_home 命令更改 java 版本。

有些程序运行需要特殊版本。所以我安装了多个版本的java。

 /usr/libexec/java_home -V            
Matching Java Virtual Machines (7):
14.0.1 (x86_64) "Oracle Corporation" - "Java SE 14.0.1" /Library/Java/JavaVirtualMachines/jdk-14.0.1.jdk/Contents/Home
13 (x86_64) "Oracle Corporation" - "Java SE 13" /Library/Java/JavaVirtualMachines/jdk-13.jdk/Contents/Home
10.0.2.0.13 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
10.0.2 (x86_64) "Oracle Corporation" - "Java SE 10.0.2" /Library/Java/JavaVirtualMachines/jdk-10.0.2.jdk/Contents/Home
1.8.0_192 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_192.jdk/Contents/Home
1.8.0_111 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home
1.7.0_80 (x86_64) "Oracle Corporation" - "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk-14.0.1.jdk/Contents/Home

我配置了 .bash_profile:

export JAVA_HOME=$(/usr/libexec/java_home)
export JAVA_7_HOME=$(/usr/libexec/java_home -v1.7)
export JAVA_8_HOME=$(/usr/libexec/java_home -v1.8)
export JAVA_10_HOME=$(/usr/libexec/java_home -v10)
export JAVA_13_HOME=$(/usr/libexec/java_home -v13)

alias jdk7="export JAVA_HOME=$JAVA_7_HOME"
alias jdk8="export JAVA_HOME=$JAVA_8_HOME"
alias jdk10="export JAVA_HOME=$JAVA_10_HOME"
alias jdk13="export JAVA_HOME=$JAVA_13_HOME"

export MAVEN_HOME=/Users/peizangpin/Program/apache-maven-3.6.3
export PATH=$PATH:$MAVEN_HOME/bin

export GRADLE_HOME=/Users/peizangpin/Program/gradle-6.7
export PATH=$PATH:$GRADLE_HOME/bin
export GRADLE_USER_HOME=/Users/peizangpin/Documents/ResuorcesPackage/gradle

export PATH=/opt/local/bin:$PATH
export PATH=/opt/local/sbin:$PATH
export PATH=/usr/local/bin:$PATH
export PATH=/usr/local/mysql/bin:$PATH
export PATH=$PATH:/usr/local/opt/go/libexec/bin
export PATH=$PATH:/usr/local/go/bin
export PATH=$PATH:/usr/local/opt/rabbitmq/sbin
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

source ~/.bashrc

至少它在 MacOS 更新之前是有效的。

但是现在:

enter image description here

它总是使用 jdk14。

这对我来说是个问题。

最佳答案

感谢@MarioStefanutti 共享链接。 Wrong JAVA_HOME after upgrade to macOS Big Sur v11.0.1

由于 JAVA_HOME 变量已设置。/usr/libexec/java_home -v {pattern} 将毫无用处。

所以,解决方案是在设置JAVA_HOME之前执行/usr/libexec/java_home -v {pattern}

export JAVA_7_HOME=$(/usr/libexec/java_home -v1.7)
export JAVA_8_HOME=$(/usr/libexec/java_home -v1.8)
export JAVA_10_HOME=$(/usr/libexec/java_home -v10)
export JAVA_13_HOME=$(/usr/libexec/java_home -v13)

# finally set JAVA_HOME
export JAVA_HOME=$(/usr/libexec/java_home)
...

关于java - 为什么 command/usr/libexec/java_home 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65168550/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com