Wrong JAVA_HOME after upgrade to macOS Big Sur v11.0.1

感情迁移 提交于 2021-01-15 02:37:13

问题


In my setup on macOS I'm working with several JDKs, switching between them via /usr/libexec/java_home tool, similar to a method described in this SO answer

After upgrading to macOS Big Sur v11.0.1, my JAVA_HOME setting stopped working, always reporting the same java version:

% /usr/libexec/java_home -V
Matching Java Virtual Machines (5):
    11.0.8 (x86_64) "AdoptOpenJDK" - "AdoptOpenJDK 11" /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
    1.8.162.12 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
    1.8.0_162 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home
    1.8.0_45 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home
    1.7.0_45 (x86_64) "Oracle Corporation" - "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home

% /usr/libexec/java_home -v 1.8.162.12
/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home

% /usr/libexec/java_home -v 1.7.0_45
/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home

回答1:


Seems in macOS Big Sur v11.0.1 the behavior of the /usr/libexec/java_home -v ... command has changed: it is sensitive to the previously set value of JAVA_HOME environment variable.

Exact behavior is not clear, I couldn't find any documentation on this, but in my experiments it reported the version already set in JAVA_HOME, regardless of the -v switch:

% JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home /usr/libexec/java_home -v 1.8.0_162
/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home

Additionally, I noticed that it reports nothing, if JAVA_HOME is set, but doesn't point to a valid java home (also for -V):

% JAVA_HOME=dummy /usr/libexec/java_home -v 1.7.0_45
% JAVA_HOME=dummy /usr/libexec/java_home -V
%

Solution is to ensure JAVA_HOME is not set before executing /usr/libexec/java_home:

% unset JAVA_HOME ; /usr/libexec/java_home -v 1.8.0_162
/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home



回答2:


As I tryed. I just delete the /Library/Internet Plug-Ins/JavaAppletPlugin.plugin and relogin. Then everything works fine.




回答3:


For me, it is totally broken. Unsetting JAVA_HOME, /usr/libexec/java_home gives:

/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home



来源:https://stackoverflow.com/questions/64917779/wrong-java-home-after-upgrade-to-macos-big-sur-v11-0-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!