记Mac系统下JD-GUI打开,提示jdk版本需要1.8+的问题
在Mac系统下JD-GUI打开报错,提示如下
看报错信息提示是本地的jdk版本过低,需要升级。在终端输入"java -version"
版本在1.8以上,应该是没问题的。然后在查下jd-gui的脚本:
# # find installed Java versions ################################# # first check system variable "$JAVA_HOME" if [ -n "$JAVA_HOME" ] ; then JAVACMD="$JAVA_HOME/bin/java" # check for specified JVMversion in "/usr/libexec/java_home" symlinks elif [ ! -z ${JVMVersion} ] && [ -x /usr/libexec/java_home ] && /usr/libexec/java_home -F; then if /usr/libexec/java_home -F -v ${JVMVersion}; then JAVACMD="`/usr/libexec/java_home -F -v ${JVMVersion} 2> /dev/null`/bin/java" else # display error message with applescript osascript -e "tell application \"System Events\" to display dialog \"ERROR launching '${CFBundleName}'\n\nNo suitable Java version found on your system!\nThis program requires Java ${JVMVersion}\nMake sure you install the required Java version.\" with title \"${CFBundleName}\" buttons {\" OK \"} default button 1 with icon path to resource \"${CFBundleIconFile}\" in bundle (path to me)" # exit with error exit 3 fi # otherwise check "/usr/libexec/java_home" symlinks elif [ -x /usr/libexec/java_home ] && /usr/libexec/java_home -F; then JAVACMD="`/usr/libexec/java_home 2> /dev/null`/bin/java" # otherwise check Java standard symlink (old Apple Java) elif [ -h /Library/Java/Home ]; then JAVACMD="/Library/Java/Home/bin/java" # fallback: public JRE plugin (Oracle Java) else JAVACMD="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java" fi
可以看到这里获取JAVACMD的过程,估计就是这里取的时候出问题了。在终端输入"echo $JAVA_HOME",结果也是正常的1.8(程序为空估计跟zsh终端有关),但是通过执行命令"/usr/libexec/java_home"得到的是jdk17的版本。
不知道是不是由于我的jdk安装在个人用户目录导致的,最后试了很多方法都没办法让/usr/libexec/java_home和JAVA_HOME保持一致,最后没办只能粗暴地改脚本把获取JAVACMD的逻辑都注释,强行设置为1.8的路径,问题算是半解决了。。。
# # find installed Java versions ################################# JAVACMD="/Users/zhugr/Library/Java/JavaVirtualMachines/adopt-openjdk-1.8.0_292/Contents/Home/bin/java" # first check system variable "$JAVA_HOME" # if [ -n "$JAVA_HOME" ] ; then # JAVACMD="$JAVA_HOME/bin/java" # # check for specified JVMversion in "/usr/libexec/java_home" symlinks # elif [ ! -z ${JVMVersion} ] && [ -x /usr/libexec/java_home ] && /usr/libexec/java_home -F; then # if /usr/libexec/java_home -F -v ${JVMVersion}; then # JAVACMD="`/usr/libexec/java_home -F -v ${JVMVersion} 2> /dev/null`/bin/java" # else # # display error message with applescript # osascript -e "tell application \"System Events\" to display dialog \"ERROR launching '${CFBundleName}'\n\nNo suitable Java version found on your system!\nThis program requires Java ${JVMVersion}\nMake sure you install the required Java version.\" with title \"${CFBundleName}\" buttons {\" OK \"} default button 1 with icon path to resource \"${CFBundleIconFile}\" in bundle (path to me)" # # exit with error # exit 3 # fi # # otherwise check "/usr/libexec/java_home" symlinks # elif [ -x /usr/libexec/java_home ] && /usr/libexec/java_home -F; then # JAVACMD="`/usr/libexec/java_home 2> /dev/null`/bin/java" # # otherwise check Java standard symlink (old Apple Java) # elif [ -h /Library/Java/Home ]; then # JAVACMD="/Library/Java/Home/bin/java" # # fallback: public JRE plugin (Oracle Java) # else # JAVACMD="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java" # fi # fallback fallback: /usr/bin/java # but this would prompt to install deprecated Apple Java 6
先记录下来,以后涨见识了再研究下
Ps:最开始的脚本获取JAVA_HOME的时候没有获取到,而通过终端能正常输出,我猜是跟shell的命令行解析终端有关,因为脚本默认是"#!/bin/sh",即通过sh终端解析,而mac默认的是zsh终端,所以获取的JAVA_HOME为空。然而我把"#!/bin/sh"改为"#!/bin/zsh"也没用,但是我直接把脚本拖进终端执行倒是可以正常打开,搞不懂。。。