Could not find tools.jar. Please check that /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home contains a valid JDK installation.
原因:java_home指向了JRE路径
通过查看java_home发现第一条是jre(JavaAppletPlugin.plugin)的路径,第二条才是jdk(jdk1.8.0_311.jdk)的路径。
JavaAppletPlugin.plugin 是 JRE
根据docs.oracle.com中的描述,得出:JavaAppletPlugin.plugin 是 JRE。
Uninstalling the JRE on macOS
jdk1.8.0_311.jdk 是 JDK
根据docs.oracle.com中的描述,得出: jdk1.8.0_311.jdk 是 JDK。
Uninstalling the JDK on macOS
解决方法
一、查看JAVA_HOME
Many Java applications need to know the location of a $JAVA_HOME directory. The $JAVA_HOME on Mac OS X should be found using the /usr/libexec/java_home command line tool on Mac OS X 10.5 or later. On older Mac OS X versions where the tool does not exist, use the fixed path “/Library/Java/Home”.
Mac查看java_home的命令:
/usr/libexec/java_home -V
命令执行结果:
/usr/libexec/java_home -V
Matching Java Virtual Machines (2):
1.8.311.11 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
1.8.0_311 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_311.jdk/Contents/Home
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
结果解读:
前提,一台返修被格式化后的新电脑,通过oracle官网下载了jdk8 311版本并安装,且并没有装过其他版本。
执行命令后发现打印出两个虚拟机:JavaAppletPlugin.plugin和jdk1.8.0_311.jdk。
二、卸载JRE
卸载jre命令:
sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
sudo rm -fr /Library/PreferencesPanes/JavaControlPanel.prefPane
三、再次查看java_home,确认是否正确
/usr/libexec/java_home -V
Matching Java Virtual Machines (1):
1.8.0_311 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_311.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk1.8.0_311.jdk/Contents/Home
附件资料
资料一、卸载Java
MAC系统 JDK 卸载及彻底删除
▌1.删除运行路径和运行环境等
sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
sudo rm -fr /Library/PreferencesPanes/JavaControlPanel.prefPane
sudo rm -fr ~/Library/Application\ Support/Java
▌2.删除当前版本的jdk
sudo rm -rf /Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk
(注:不确定版本号先查看当前版本 ls /Library/Java/JavaVirtualMachines/ )
▌3.检查是否卸载成功
java -version
▌另外,官方资料如下:
如何在 Mac 上卸载 Java?
Depending on your installation, see the related link:
“卸载JRE”
“卸载JDK”
官方文档:
https://docs.oracle.com/javase/8/docs/technotes/guides/install/mac_install_faq.html#A1097743
资料二、卸载JRE(JavaAppletPlugin.plugin)
To uninstall the JRE, you must have Administrator privileges and execute the remove commands either as root or by using the sudo(8) tool.
Remove one directory and one file (a symlink), as follows:
Navigate to /Library/Internet Plug-Ins and remove the JavaAppletPlugin.plugin directory.
Navigate to /Library/PreferencePanes and remove JavaControlPanel.prefpane.
Do not attempt to uninstall Java by removing the Java tools from /usr/bin. This directory is part of the system software and any changes will be reset by Apple the next time you perform an update of the OS.
官方文档:《JRE的安装与卸载》
https://docs.oracle.com/javase/8/docs/technotes/guides/install/mac_jre.html#A1096890
资料三、卸载JDK(jdk1.8.0_311.jdk)
To uninstall the JDK, you must have Administrator privileges and execute the remove command either as root or by using the sudo(8) tool.
Navigate to /Library/Java/JavaVirtualMachines and remove the directory whose name matches the following format:Foot1
/Library/Java/JavaVirtualMachines/jdkmajor.minor.macro[_update].jdk
For example, to uninstall 8u6:
% rm -rf jdk1.8.0_06.jdk
Do not attempt to uninstall Java by removing the Java tools from /usr/bin. This directory is part of the system software and any changes will be reset by Apple the next time you perform an update of the OS.
官方文档:《JDK的安装与卸载》
https://docs.oracle.com/javase/8/docs/technotes/guides/install/mac_jdk.html#CHDBADCG
资料四:下载最新版的JDK并安装:
https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html