关于jd-gui启动报This program requires Java 1.8+的错误问题及解决方法

2022-07-14,,,,

最近,在mac使用上jd-gui启动时,报了如下的错误

error launching 'jd-gui'
no suitable java version found on your system!
this program requires java 1.8+
make sure you install the required java version.

解决方法

在“访达”中,右击jd-gui图标,点击“显示包内容”。

然后,打开“contents/macos/universaljavaapplicationstub.sh”文件,使用以下内容替换,保存即可。

#!/bin/bash
##################################################################################
#                                                                                #
# universaljavaapplicationstub                                                   #
#                                                                                #
# a bash based javaapplicationstub for java apps on mac os x                     #
# that works with both apple's and oracle's plist format.                        #
#                                                                                #
# inspired by ian roberts stackoverflow answer                                   #
# at http://stackoverflow.com/a/17546508/1128689                                 #
#                                                                                #
# @author    tobias fischer                                                      #
# @url       https://github.com/tofi86/universaljavaapplicationstub              #
# @date      2020-03-19                                                          #
# @version   3.0.6                                                               #
#                                                                                #
##################################################################################
#                                                                                #
# the mit license (mit)                                                          #
#                                                                                #
# copyright (c) 2014-2020 tobias fischer                                         #
#                                                                                #
# permission is hereby granted, free of charge, to any person obtaining a copy   #
# of this software and associated documentation files (the "software"), to deal  #
# in the software without restriction, including without limitation the rights   #
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell      #
# copies of the software, and to permit persons to whom the software is          #
# furnished to do so, subject to the following conditions:                       #
#                                                                                #
# the above copyright notice and this permission notice shall be included in all #
# copies or substantial portions of the software.                                #
#                                                                                #
# the software is provided "as is", without warranty of any kind, express or     #
# implied, including but not limited to the warranties of merchantability,       #
# fitness for a particular purpose and noninfringement. in no event shall the    #
# authors or copyright holders be liable for any claim, damages or other         #
# liability, whether in an action of contract, tort or otherwise, arising from,  #
# out of or in connection with the software or the use or other dealings in the  #
# software.                                                                      #
#                                                                                #
##################################################################################
 
 
 
# function 'stub_logger()'
#
# a logger which logs to the macos console.app using the 'syslog' command
#
# @param1  the log message
# @return  void
################################################################################
function stub_logger() {
    syslog -s -k \
        facility com.apple.console \
        level notice \
        sender "$(basename "$0")" \
        message "[$$][${cfbundlename:-$(basename "$0")}] $1"
}
 
 
 
# set the directory abspath of the current
# shell script with symlinks being resolved
############################################
 
prg=$0
while [ -h "$prg" ]; do
    ls=$(ls -ld "$prg")
    link=$(expr "$ls" : '^.*-> \(.*\)$' 2>/dev/null)
    if expr "$link" : '^/' 2> /dev/null >/dev/null; then
        prg="$link"
    else
        prg="$(dirname "$prg")/$link"
    fi
done
progdir=$(dirname "$prg")
stub_logger "[stubdir] $progdir"
 
 
 
# set files and folders
############################################
 
# the absolute path of the app package
cd "$progdir"/../../ || exit 11
apppackagefolder=$(pwd)
 
# the base path of the app package
cd .. || exit 12
apppackageroot=$(pwd)
 
# set apple's java folder
applejavafolder="${apppackagefolder}"/contents/resources/java
 
# set apple's resources folder
appleresourcesfolder="${apppackagefolder}"/contents/resources
 
# set oracle's java folder
oraclejavafolder="${apppackagefolder}"/contents/java
 
# set oracle's resources folder
oracleresourcesfolder="${apppackagefolder}"/contents/resources
 
# set path to info.plist in bundle
infoplistfile="${apppackagefolder}"/contents/info.plist
 
# set the default jvm version to a null string
jvmversion=""
jvmmaxversion=""
 
 
 
# function 'plist_get()'
#
# read a specific plist key with 'plistbuddy' utility
#
# @param1  the plist key with leading colon ':'
# @return  the value as string or array
################################################################################
plist_get(){
    /usr/libexec/plistbuddy -c "print $1" "${infoplistfile}" 2> /dev/null
}
 
# function 'plist_get_java()'
#
# read a specific plist key with 'plistbuddy' utility
# in the 'java' or 'javax' dictionary (<dict>)
#
# @param1  the plist :java(x):key with leading colon ':'
# @return  the value as string or array
################################################################################
plist_get_java(){
    plist_get ${javakey:-":java"}$1
}
 
 
 
# read info.plist and extract jvm options
############################################
 
# read the program name from cfbundlename
cfbundlename=$(plist_get ':cfbundlename')
 
# read the icon file name
cfbundleiconfile=$(plist_get ':cfbundleiconfile')
 
 
# check info.plist for apple style java keys -> if key :java is present, parse in apple mode
/usr/libexec/plistbuddy -c "print :java" "${infoplistfile}" > /dev/null 2>&1
exitcode=$?
javakey=":java"
 
# if no :java key is present, check info.plist for universaljavaapplication style javax keys -> if key :javax is present, parse in apple mode
if [ $exitcode -ne 0 ]; then
    /usr/libexec/plistbuddy -c "print :javax" "${infoplistfile}" > /dev/null 2>&1
    exitcode=$?
    javakey=":javax"
fi
 
 
# read 'info.plist' file in apple style if exit code returns 0 (true, ':java' key is present)
if [ $exitcode -eq 0 ]; then
    stub_logger "[pliststyle] apple"
 
    # set java and resources folder
    javafolder="${applejavafolder}"
    resourcesfolder="${appleresourcesfolder}"
 
    app_package="${apppackagefolder}"
    javaroot="${applejavafolder}"
    user_home="$home"
 
 
    # read the java workingdirectory
    jvmworkdir=$(plist_get_java ':workingdirectory' | xargs)
    # set working directory based upon plist value
    if [[ ! -z ${jvmworkdir} ]]; then
        workingdirectory="${jvmworkdir}"
    else
        # apppackageroot is the standard workingdirectory when the script is started
        workingdirectory="${apppackageroot}"
    fi
    # expand variables $app_package, $javaroot, $user_home
    workingdirectory=$(eval echo "${workingdirectory}")
 
 
    # read the mainclass name
    jvmmainclass="$(plist_get_java ':mainclass')"
 
    # read the splashfile name
    jvmsplashfile=$(plist_get_java ':splashfile')
 
    # read the jvm properties as an array and retain spaces
    ifs=$'\t\n'
    jvmoptions=($(xargs -n1 <<<$(plist_get_java ':properties' | grep " =" | sed 's/^ */-d/g' | sed -e 's/ = (.*)$/="\1"/g')))
    unset ifs
    # post processing of the array follows further below...
 
    # read the classpath in either array or string style
    jvmclasspath_raw=$(plist_get_java ':classpath' | xargs)
    if [[ $jvmclasspath_raw == *array* ]] ; then
        jvmclasspath=.$(plist_get_java ':classpath' | grep "    " | sed 's/^ */:/g' | tr -d '\n' | xargs)
    else
        jvmclasspath=${jvmclasspath_raw}
    fi
    # expand variables $app_package, $javaroot, $user_home
    jvmclasspath=$(eval echo "${jvmclasspath}")
 
    # read the jvm options in either array or string style
    jvmdefaultoptions_raw=$(plist_get_java ':vmoptions' | xargs)
    if [[ $jvmdefaultoptions_raw == *array* ]] ; then
        jvmdefaultoptions=$(plist_get_java ':vmoptions' | grep "    " | sed 's/^ */ /g' | tr -d '\n' | xargs)
    else
        jvmdefaultoptions=${jvmdefaultoptions_raw}
    fi
 
    # read startonmainthread and add as -xstartonfirstthread
    jvmstartonmainthread=$(plist_get_java ':startonmainthread')
    if [ "${jvmstartonmainthread}" == "true" ]; then
        jvmdefaultoptions+=" -xstartonfirstthread"
    fi
 
    # read the jvm arguments in either array or string style (#76) and retain spaces
    ifs=$'\t\n'
    mainargs_raw=$(plist_get_java ':arguments' | xargs)
    if [[ $mainargs_raw == *array* ]] ; then
        mainargs=($(xargs -n1 <<<$(plist_get_java ':arguments' | tr -d '\n' | sed -e 's/array \{ *(.*) *\}/\1/g' | sed 's/  */ /g')))
    else
        mainargs=($(xargs -n1 <<<$(plist_get_java ':arguments')))
    fi
    unset ifs
    # post processing of the array follows further below...
 
    # read the java version we want to find
    jvmversion=$(plist_get_java ':jvmversion' | xargs)
    # post processing of the version string follows below...
 
 
# read 'info.plist' file in oracle style
else
    stub_logger "[pliststyle] oracle"
 
    # set working directory and java and resources folder
    javafolder="${oraclejavafolder}"
    resourcesfolder="${oracleresourcesfolder}"
    workingdirectory="${oraclejavafolder}"
 
    app_root="${apppackagefolder}"
 
    # read the mainclass name
    jvmmainclass="$(plist_get ':jvmmainclassname')"
 
    # read the splashfile name
    jvmsplashfile=$(plist_get ':jvmsplashfile')
 
    # read the jvm options as an array and retain spaces
    ifs=$'\t\n'
    jvmoptions=($(plist_get ':jvmoptions' | grep "    " | sed 's/^ *//g'))
    unset ifs
    # post processing of the array follows further below...
 
    # read the classpath in either array or string style
    jvmclasspath_raw=$(plist_get ':jvmclasspath')
    if [[ $jvmclasspath_raw == *array* ]] ; then
        jvmclasspath=.$(plist_get ':jvmclasspath' | grep "    " | sed 's/^ */:/g' | tr -d '\n' | xargs)
        # expand variables $app_package, $javaroot, $user_home
        jvmclasspath=$(eval echo "${jvmclasspath}")
 
    elif [[ ! -z ${jvmclasspath_raw} ]] ; then
        jvmclasspath=${jvmclasspath_raw}
        # expand variables $app_package, $javaroot, $user_home
        jvmclasspath=$(eval echo "${jvmclasspath}")
 
    else
        #default: fallback to oraclejavafolder
        jvmclasspath="${javafolder}/*"
        # do not expand the default 'appname.app/contents/java/*' classpath (#42)
    fi
 
    # read the jvm default options
    jvmdefaultoptions=$(plist_get ':jvmdefaultoptions' | grep -o " \-.*" | tr -d '\n' | xargs)
 
    # read the main arguments from jvmarguments key as an array and retain spaces (see #46 for naming details)
    ifs=$'\t\n'
    mainargs=($(xargs -n1 <<<$(plist_get ':jvmarguments' | tr -d '\n' | sed -e 's/array \{ *(.*) *\}/\1/g' | sed 's/  */ /g')))
    unset ifs
    # post processing of the array follows further below...
 
    # read the java version we want to find
    jvmversion=$(plist_get ':jvmversion' | xargs)
    # post processing of the version string follows below...
fi
 
 
# (#75) check for undefined icons or icon names without .icns extension and prepare
# an osascript statement for those cases when the icon can be shown in the dialog
dialogwithicon=""
if [ ! -z ${cfbundleiconfile} ]; then
    if [[ ${cfbundleiconfile} == *.icns ]] && [[ -f "${resourcesfolder}/${cfbundleiconfile}" ]] ; then
        dialogwithicon=" with icon path to resource \"${cfbundleiconfile}\" in bundle (path to me)"
    elif [[ ${cfbundleiconfile} != *.icns ]] && [[ -f "${resourcesfolder}/${cfbundleiconfile}.icns" ]] ; then
        cfbundleiconfile+=".icns"
        dialogwithicon=" with icon path to resource \"${cfbundleiconfile}\" in bundle (path to me)"
    fi
fi
 
 
# jvmversion: post processing and optional splitting
if [[ ${jvmversion} == *";"* ]]; then
    minmaxarray=(${jvmversion//;/ })
    jvmversion=${minmaxarray[0]//+}
    jvmmaxversion=${minmaxarray[1]//+}
fi
stub_logger "[javarequirement] jvm minimum version: ${jvmversion}"
stub_logger "[javarequirement] jvm maximum version: ${jvmmaxversion}"
 
# mainargs: replace occurences of $app_root with its content
mainargsarr=()
for i in "${mainargs[@]}"
do
    mainargsarr+=("$(eval echo "$i")")
done
 
# jvmoptions: replace occurences of $app_root with its content
jvmoptionsarr=()
for i in "${jvmoptions[@]}"
do
    jvmoptionsarr+=("$(eval echo "$i")")
done
 
 
# internationalized messages
############################################
 
lang=$(defaults read -g applelocale)
stub_logger "[language] $lang"
 
# french localization
if [[ $lang == fr* ]] ; then
    msg_error_launching="erreur au lancement de '${cfbundlename}'."
    msg_missing_mainclass="'mainclass' n'est pas spécifié.\nl'application java ne peut pas être lancée."
    msg_jvmversion_req_invalid="la syntaxe de la version de java demandée est invalide: %s\nveuillez contacter le développeur de l'application."
    msg_no_suitable_java="la version de java installée sur votre système ne convient pas.\nce programme nécessite java %s"
    msg_java_version_or_later="ou ultérieur"
    msg_java_version_latest="(dernière mise à jour)"
    msg_java_version_max="à %s"
    msg_no_suitable_java_check="merci de bien vouloir installer la version de java requise."
    msg_install_java="java doit être installé sur votre système.\nrendez-vous sur java.com et suivez les instructions d'installation..."
    msg_later="plus tard"
    msg_visit_java_dot_com="java by oracle"
    msg_visit_adoptopenjdk="java by adoptopenjdk"
 
# german localization
elif [[ $lang == de* ]] ; then
    msg_error_launching="fehler beim starten von '${cfbundlename}'."
    msg_missing_mainclass="die 'mainclass' ist nicht spezifiziert!\ndie java-anwendung kann nicht gestartet werden!"
    msg_jvmversion_req_invalid="die syntax der angeforderten java-version ist ungültig: %s\nbitte kontaktieren sie den entwickler der app."
    msg_no_suitable_java="es wurde keine passende java-version auf ihrem system gefunden!\ndieses programm benötigt java %s"
    msg_java_version_or_later="oder neuer"
    msg_java_version_latest="(neuste unterversion)"
    msg_java_version_max="bis %s"
    msg_no_suitable_java_check="stellen sie sicher, dass die angeforderte java-version installiert ist."
    msg_install_java="auf ihrem system muss die 'java'-software installiert sein.\nbesuchen sie java.com für weitere installationshinweise."
    msg_later="später"
    msg_visit_java_dot_com="java von oracle"
    msg_visit_adoptopenjdk="java von adoptopenjdk"
 
# simplifyed chinese localization
elif [[ $lang == zh* ]] ; then
    msg_error_launching="无法启动 '${cfbundlename}'."
    msg_missing_mainclass="没有指定 'mainclass'!\njava程序无法启动!"
    msg_jvmversion_req_invalid="java版本参数语法错误: %s\n请联系该应用的开发者。"
    msg_no_suitable_java="没有在系统中找到合适的java版本!\n必须安装java %s才能够使用该程序!"
    msg_java_version_or_later="及以上版本"
    msg_java_version_latest="(最新版本)"
    msg_java_version_max="最高为 %s"
    msg_no_suitable_java_check="请确保系统中安装了所需的java版本"
    msg_install_java="你需要在mac中安装java运行环境!\n访问 java.com 了解如何安装。"
    msg_later="稍后"
    msg_visit_java_dot_com="java by oracle"
    msg_visit_adoptopenjdk="java by adoptopenjdk"
 
# english default localization
else
    msg_error_launching="error launching '${cfbundlename}'."
    msg_missing_mainclass="'mainclass' isn't specified!\njava application cannot be started!"
    msg_jvmversion_req_invalid="the syntax of the required java version is invalid: %s\nplease contact the app developer."
    msg_no_suitable_java="no suitable java version found on your system!\nthis program requires java %s"
    msg_java_version_or_later="or later"
    msg_java_version_latest="(latest update)"
    msg_java_version_max="up to %s"
    msg_no_suitable_java_check="make sure you install the required java version."
    msg_install_java="you need to have java installed on your mac!\nvisit java.com for installation instructions..."
    msg_later="later"
    msg_visit_java_dot_com="java by oracle"
    msg_visit_adoptopenjdk="java by adoptopenjdk"
fi
 
 
 
# function 'get_java_version_from_cmd()'
#
# returns java version string from 'java -version' command
# works for both old (1.8) and new (9) version schema
#
# @param1  path to a java jvm executable
# @return  the java version number as displayed in 'java -version' command
################################################################################
function get_java_version_from_cmd() {
    # second sed command strips " and -ea from the version string
    echo $("$1" -version 2>&1 | awk '/version/{print $3}' | sed -e 's/"//g;s/-ea//g')
}
 
 
# function 'extract_java_major_version()'
#
# extract java major version from a version string
#
# @param1  a java version number ('1.8.0_45') or requirement string ('1.8+')
# @return  the major version (e.g. '7', '8' or '9', etc.)
################################################################################
function extract_java_major_version() {
    echo $(echo "$1" | sed -e 's/^1\.//;s/^([0-9]+)(-ea|(\.[0-9_.]{1,7})?)(-b[0-9]+-[0-9]+)?[+*]?$/\1/')
}
 
 
# function 'get_comparable_java_version()'
#
# return comparable version for a java version number or requirement string
#
# @param1  a java version number ('1.8.0_45') or requirement string ('1.8+')
# @return  an 8 digit numeral ('1.8.0_45'->'08000045'; '9.1.13'->'09001013')
################################################################################
function get_comparable_java_version() {
    # cleaning: 1) remove leading '1.'; 2) remove build string (e.g. '-b14-468'); 3) remove 'a-z' and '-*+' (e.g. '-ea'); 4) replace '_' with '.'
    local cleaned=$(echo "$1" | sed -e 's/^1\.//g;s/-b[0-9]+-[0-9]+$//g;s/[a-za-z+*\-]//g;s/_/./g')
    # splitting at '.' into an array
    local arr=( ${cleaned//./ } )
    # echo a string with left padded version numbers
    echo "$(printf '%02s' ${arr[0]})$(printf '%03s' ${arr[1]})$(printf '%03s' ${arr[2]})"
}
 
 
# function 'is_valid_requirement_pattern()'
#
# check whether the java requirement is a valid requirement pattern
#
# supported requirements are for example:
# - 1.6       requires java 6 (any update)      [1.6, 1.6.0_45, 1.6.0_88]
# - 1.6*      requires java 6 (any update)      [1.6, 1.6.0_45, 1.6.0_88]
# - 1.6+      requires java 6 or higher         [1.6, 1.6.0_45, 1.8, 9, etc.]
# - 1.6.0     requires java 6 (any update)      [1.6, 1.6.0_45, 1.6.0_88]
# - 1.6.0_45  requires java 6u45                [1.6.0_45]
# - 1.6.0_45+ requires java 6u45 or higher      [1.6.0_45, 1.6.0_88, 1.8, etc.]
# - 9         requires java 9 (any update)      [9.0.*, 9.1, 9.3, etc.]
# - 9*        requires java 9 (any update)      [9.0.*, 9.1, 9.3, etc.]
# - 9+        requires java 9 or higher         [9.0, 9.1, 10, etc.]
# - 9.1       requires java 9.1 (any update)    [9.1.*, 9.1.2, 9.1.13, etc.]
# - 9.1*      requires java 9.1 (any update)    [9.1.*, 9.1.2, 9.1.13, etc.]
# - 9.1+      requires java 9.1 or higher       [9.1, 9.2, 10, etc.]
# - 9.1.3     requires java 9.1.3               [9.1.3]
# - 9.1.3*    requires java 9.1.3 (any update)  [9.1.3]
# - 9.1.3+    requires java 9.1.3 or higher     [9.1.3, 9.1.4, 9.2.*, 10, etc.]
# - 10-ea     requires java 10 (early access release)
#
# unsupported requirement patterns are for example:
# - 1.2, 1.3, 1.9       java 2, 3 are not supported
# - 1.9                 java 9 introduced a new versioning scheme
# - 6u45                known versioning syntax, but unsupported
# - 9-ea*, 9-ea+        early access releases paired with */+
# - 9., 9.*, 9.+        version ending with a .
# - 9.1., 9.1.*, 9.1.+  version ending with a .
# - 9.3.5.6             4 part version number is unsupported
#
# @param1  a java requirement string ('1.8+')
# @return  boolean exit code: 0 (is valid), 1 (is not valid)
################################################################################
function is_valid_requirement_pattern() {
    local java_req=$1
    java8pattern='1\.[4-8](\.[0-9]+)?(\.0_[0-9]+)?[*+]?'
    java9pattern='(9|1[0-9])(-ea|[*+]|(\.[0-9]+){1,2}[*+]?)?'
    # test matches either old java versioning scheme (up to 1.8) or new scheme (starting with 9)
    if [[ ${java_req} =~ ^(${java8pattern}|${java9pattern})$ ]]; then
        return 0
    else
        return 1
    fi
}
 
 
 
# determine which jvm to use
############################################
 
# default apple jre plugin path (< 1.6)
apple_jre_plugin="/library/java/home/bin/java"
apple_jre_version=$(get_java_version_from_cmd "${apple_jre_plugin}")
# default oracle jre plugin path (>= 1.7)
oracle_jre_plugin="/library/internet plug-ins/javaappletplugin.plugin/contents/home/bin/java"
oracle_jre_version=$(get_java_version_from_cmd "${oracle_jre_plugin}")
 
 
# first check system variable "$java_home" -> has precedence over any other system jvm
stub_logger '[javasearch] checking for $java_home ...'
if [ -n "$java_home" ] ; then
    stub_logger "[javasearch] ... found java_home with value $java_home"
 
    # pr 26: allow specifying "$java_home" relative to "$apppackagefolder"
    # which allows for bundling a custom version of java inside your app!
    if [[ $java_home == /* ]] ; then
        # if "$java_home" starts with a slash it's an absolute path
        javacmd="$java_home/bin/java"
    else
        # otherwise it's a relative path to "$apppackagefolder"
        javacmd="$apppackagefolder/$java_home/bin/java"
    fi
    javacmd_version=$(get_comparable_java_version $(get_java_version_from_cmd "${javacmd}"))
else
    stub_logger "[javasearch] ... didn't found java_home"
fi
 
 
# check for any other or a specific java version
# also if $java_home exists but isn't executable
if [ -z "${javacmd}" ] || [ ! -x "${javacmd}" ] ; then
    stub_logger "[javasearch] checking for javavirtualmachines on the system ..."
    # reset variables
    javacmd=""
    javacmd_version=""
 
    # first check whether jvmversion string is a valid requirement string
    if [ ! -z "${jvmversion}" ] && ! is_valid_requirement_pattern ${jvmversion} ; then
        msg_jvmversion_req_invalid_expanded=$(printf "${msg_jvmversion_req_invalid}" "${jvmversion}")
        # log exit cause
        stub_logger "[exit 4] ${msg_jvmversion_req_invalid_expanded}"
        # display error message with applescript
        osascript -e "tell application \"system events\" to display dialog \"${msg_error_launching}\n\n${msg_jvmversion_req_invalid_expanded}\" with title \"${cfbundlename}\" buttons {\" ok \"} default button 1${dialogwithicon}"
        # exit with error
        exit 4
    fi
    # then check whether jvmmaxversion string is a valid requirement string
    if [ ! -z "${jvmmaxversion}" ] && ! is_valid_requirement_pattern ${jvmmaxversion} ; then
        msg_jvmversion_req_invalid_expanded=$(printf "${msg_jvmversion_req_invalid}" "${jvmmaxversion}")
        # log exit cause
        stub_logger "[exit 5] ${msg_jvmversion_req_invalid_expanded}"
        # display error message with applescript
        osascript -e "tell application \"system events\" to display dialog \"${msg_error_launching}\n\n${msg_jvmversion_req_invalid_expanded}\" with title \"${cfbundlename}\" buttons {\" ok \"} default button 1${dialogwithicon}"
        # exit with error
        exit 5
    fi
 
 
    # find installed javavirtualmachines (jdk + jre)
    alljvms=()
    # read jdk's from '/usr/libexec/java_home -v' command
    while read -r line; do
        version=$(echo $line | awk -f $',' '{print $1;}')
        path=$(echo $line | awk -f $'" ' '{print $2;}')
        path+="/bin/java"
        alljvms+=("$version:$path")
    done < <(/usr/libexec/java_home -v 2>&1 | grep '^[[:space:]]')
    # unset while loop variables
    unset version path
 
    # add apple jre if available
    if [ -x "${apple_jre_plugin}" ] ; then
        alljvms+=("$apple_jre_version:$apple_jre_plugin")
    fi
 
    # add oracle jre if available
    if [ -x "${oracle_jre_plugin}" ] ; then
        alljvms+=("$oracle_jre_version:$oracle_jre_plugin")
    fi
 
    # debug output
    for i in "${alljvms[@]}"
    do
        stub_logger "[javasearch] ... found jvm: $i"
    done
 
 
    # determine jvms matching the min/max version requirement
    minc=$(get_comparable_java_version ${jvmversion})
    maxc=$(get_comparable_java_version ${jvmmaxversion})
    matchingjvms=()
 
    for i in "${alljvms[@]}"
    do
        # split jvm string at ':' delimiter to retain spaces in $path substring
        ifs=: arr=($i) ; unset ifs
        # [0] jvm version number
        ver=${arr[0]}
        # comparable jvm version number
        comp=$(get_comparable_java_version $ver)
        # [1] jvm path
        path="${arr[1]}"
        # construct string item for adding to the "matchingjvms" array
        item="$comp:$ver:$path"
 
        # pre-requisite: current version number needs to be greater than min version number
        if [ "$comp" -ge "$minc" ] ; then
 
            # perform max version checks if max version requirement is present
            if [ ! -z ${jvmmaxversion} ] ; then
 
                # max version requirement ends with '*' modifier
                if [[ ${jvmmaxversion} == *\* ]] ; then
 
                    # use the '*' modifier from the max version string as wildcard for a 'starts with' comparison
                    # and check whether the current version number starts with the max version wildcard string
                    if [[ ${ver} == ${jvmmaxversion} ]]; then
                        matchingjvms+=("$item")
 
                    # or whether the current comparable version is lower than the comparable max version
                    elif [ "$comp" -le "$maxc" ] ; then
                        matchingjvms+=("$item")
                    fi
 
                # max version requirement ends with '+' modifier -> always add this version if it's greater than $min
                # because a max requirement with + modifier doesn't make sense
                elif [[ ${jvmmaxversion} == *+ ]] ; then
                    matchingjvms+=("$item")
 
                # matches 6 zeros at the end of the max version string (e.g. for 1.8, 9)
                # -> then the max version string should be treated like with a '*' modifier at the end
                #elif [[ ${maxc} =~ ^[0-9]{2}0{6}$ ]] && [ "$comp" -le $(( ${maxc#0} + 999 )) ] ; then
                #    matchingjvms+=("$item")
 
                # matches 3 zeros at the end of the max version string (e.g. for 9.1, 10.3)
                # -> then the max version string should be treated like with a '*' modifier at the end
                #elif [[ ${maxc} =~ ^[0-9]{5}0{3}$ ]] && [ "$comp" -le "${maxc}" ] ; then
                #    matchingjvms+=("$item")
 
                # matches standard requirements without modifier
                elif [ "$comp" -le "$maxc" ]; then
                    matchingjvms+=("$item")
                fi
 
            # no max version requirement:
 
            # min version requirement ends with '+' modifier
            # -> always add the current version because it's greater than $min
            elif [[ ${jvmversion} == *+ ]] ; then
                matchingjvms+=("$item")
 
            # min version requirement ends with '*' modifier
            # -> use the '*' modifier from the min version string as wildcard for a 'starts with' comparison
            #    and check whether the current version number starts with the min version wildcard string
            elif [[ ${jvmversion} == *\* ]] ; then
                if [[ ${ver} == ${jvmversion} ]] ; then
                    matchingjvms+=("$item")
                fi
 
            # compare the min version against the current version with an additional * wildcard for a 'starts with' comparison
            # -> e.g. add 1.8.0_44 when the requirement is 1.8
            elif [[ ${ver} == ${jvmversion}* ]] ; then
                    matchingjvms+=("$item")
            fi
        fi
    done
    # unset for loop variables
    unset arr ver comp path item
 
    # debug output
    for i in "${matchingjvms[@]}"
    do
        stub_logger "[javasearch] ... ... matches all requirements: $i"
    done
 
 
    # sort the matching javavirtualmachines by version number
    # https://stackoverflow.com/a/11789688/1128689
    ifs=$'\n' matchingjvms=($(sort -nr <<<"${matchingjvms[*]}"))
    unset ifs
 
 
    # get the highest matching jvm
    for ((i = 0; i < ${#matchingjvms[@]}; i++));
    do
        # split jvm string at ':' delimiter to retain spaces in $path substring
        ifs=: arr=(${matchingjvms[$i]}) ; unset ifs
        # [0] comparable jvm version number
        comp=${arr[0]}
        # [1] jvm version number
        ver=${arr[1]}
        # [2] jvm path
        path="${arr[2]}"
 
        # use current value as javacmd if it's executable
        if [ -x "$path" ] ; then
            javacmd="$path"
            javacmd_version=$comp
            break
        fi
    done
    # unset for loop variables
    unset arr comp ver path
fi
 
# log the java command and the extracted version number
stub_logger "[javacommand] '$javacmd'"
stub_logger "[javaversion] $(get_java_version_from_cmd "${javacmd}")${javacmd_version:+ / $javacmd_version}"
 
 
 
if [ -z "${javacmd}" ] || [ ! -x "${javacmd}" ] ; then
 
    # different error messages when a specific jvm was required
    if [ ! -z "${jvmversion}" ] ; then
        # display human readable java version (#28)
        java_version_hr=$(echo ${jvmversion} | sed -e 's/^1\.([0-9+*]+)$/ \1/g' | sed "s/+/ ${msg_java_version_or_later}/;s/*/ ${msg_java_version_latest}/")
        msg_no_suitable_java_expanded=$(printf "${msg_no_suitable_java}" "${java_version_hr}").
 
        if [ ! -z "${jvmmaxversion}" ] ; then
            java_version_hr=$(extract_java_major_version ${jvmversion})
            java_version_max_hr=$(echo ${jvmmaxversion} | sed -e 's/^1\.([0-9+*]+)$/ \1/g' | sed "s/+//;s/*/ ${msg_java_version_latest}/")
            msg_no_suitable_java_expanded="$(printf "${msg_no_suitable_java}" "${java_version_hr}") $(printf "${msg_java_version_max}" "${java_version_max_hr}")"
        fi
 
        # log exit cause
        stub_logger "[exit 3] ${msg_no_suitable_java_expanded}"
 
        # display error message with applescript
        osascript -e "tell application \"system events\" to display dialog \"${msg_error_launching}\n\n${msg_no_suitable_java_expanded}\n${msg_no_suitable_java_check}\" with title \"${cfbundlename}\"  buttons {\" ok \", \"${msg_visit_java_dot_com}\", \"${msg_visit_adoptopenjdk}\"} default button 1${dialogwithicon}" \
                -e "set response to button returned of the result" \
                -e "if response is \"${msg_visit_java_dot_com}\" then open location \"https://www.java.com/download/\"" \
                -e "if response is \"${msg_visit_adoptopenjdk}\" then open location \"https://adoptopenjdk.net/releases.html\""
        # exit with error
        exit 3
 
    else
        # log exit cause
        stub_logger "[exit 1] ${msg_error_launching}"
        # display error message with applescript
        osascript -e "tell application \"system events\" to display dialog \"${msg_error_launching}\n\n${msg_install_java}\" with title \"${cfbundlename}\" buttons {\"${msg_later}\", \"${msg_visit_java_dot_com}\", \"${msg_visit_adoptopenjdk}\"} default button 1${dialogwithicon}" \
                    -e "set response to button returned of the result" \
                    -e "if response is \"${msg_visit_java_dot_com}\" then open location \"https://www.java.com/download/\"" \
                    -e "if response is \"${msg_visit_adoptopenjdk}\" then open location \"https://adoptopenjdk.net/releases.html\""
        # exit with error
        exit 1
    fi
fi
 
 
 
# mainclass check
############################################
 
if [ -z "${jvmmainclass}" ]; then
    # log exit cause
    stub_logger "[exit 2] ${msg_missing_mainclass}"
    # display error message with applescript
    osascript -e "tell application \"system events\" to display dialog \"${msg_error_launching}\n\n${msg_missing_mainclass}\" with title \"${cfbundlename}\" buttons {\" ok \"} default button 1${dialogwithicon}"
    # exit with error
    exit 2
fi
 
 
 
# execute $javacmd and do some preparation
############################################
 
# enable drag&drop to the dock icon
export cfprocesspath="$0"
 
# remove apples processserialnumber from passthru arguments (#39)
if [[ "$*" == -psn* ]] ; then
    argspassthru=()
else
    argspassthru=("$@")
fi
 
# change to working directory based upon apple/oracle plist info
cd "${workingdirectory}" || exit 13
stub_logger "[workingdirectory] ${workingdirectory}"
 
# execute java and set
# - classpath
# - splash image
# - dock icon
# - app name
# - jvm options / properties (-d)
# - jvm default options (-x)
# - main class
# - main class arguments
# - passthrough arguments from terminal or drag'n'drop to finder icon
stub_logger "[exec] \"$javacmd\" -cp \"${jvmclasspath}\" -splash:\"${resourcesfolder}/${jvmsplashfile}\" -xdock:icon=\"${resourcesfolder}/${cfbundleiconfile}\" -xdock:name=\"${cfbundlename}\" ${jvmoptionsarr:+$(printf "'%s' " "${jvmoptionsarr[@]}") }${jvmdefaultoptions:+$jvmdefaultoptions }${jvmmainclass}${mainargsarr:+ $(printf "'%s' " "${mainargsarr[@]}")}${argspassthru:+ $(printf "'%s' " "${argspassthru[@]}")}"
exec "${javacmd}" \
        -cp "${jvmclasspath}" \
        -splash:"${resourcesfolder}/${jvmsplashfile}" \
        -xdock:icon="${resourcesfolder}/${cfbundleiconfile}" \
        -xdock:name="${cfbundlename}" \
        ${jvmoptionsarr:+"${jvmoptionsarr[@]}" }\
        ${jvmdefaultoptions:+$jvmdefaultoptions }\
        "${jvmmainclass}"\
        ${mainargsarr:+ "${mainargsarr[@]}"}\
        ${argspassthru:+ "${argspassthru[@]}"}

到此这篇关于关于jd-gui启动报this program requires java 1.8+的错误的文章就介绍到这了,更多相关jd-gui启动报错内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!

《关于jd-gui启动报This program requires Java 1.8+的错误问题及解决方法.doc》

下载本文的Word格式文档,以方便收藏与打印。