diff --git a/scripts/start-configuration b/scripts/start-configuration index aec768e6..48f47475 100755 --- a/scripts/start-configuration +++ b/scripts/start-configuration @@ -36,7 +36,7 @@ if isTrue "$PREFER_IPV6"; then export JVM_DD_OPTS fi -if (( $(mc-image-helper java-release) >= 17 )); then +if (( $(getJavaRelease) >= 17 )); then MC_IMAGE_HELPER_OPTS+=" --enable-native-access=ALL-UNNAMED" export MC_IMAGE_HELPER_OPTS fi diff --git a/scripts/start-utils b/scripts/start-utils index 7db9977b..d9ea4898 100755 --- a/scripts/start-utils +++ b/scripts/start-utils @@ -646,6 +646,23 @@ function getDistro() { grep -E "^ID=" /etc/os-release | cut -d= -f2 | sed -e 's/"//g' } +function getJavaRelease() { + # Read the major version from the JDK's release file so no JVM has to start; + # the helper is the fallback when the file is missing. + local version + if [[ ${JAVA_HOME:-} && -f "$JAVA_HOME/release" ]]; then + version=$(sed -n -e 's/^JAVA_VERSION="\(.*\)"$/\1/p' "$JAVA_HOME/release") + # Java 8 and earlier report 1.8.0_312 and so on + version=${version#1.} + version=${version%%[._-]*} + fi + if isNumeric "${version:-}"; then + echo "$version" + else + mc-image-helper java-release + fi +} + function checkSum() { local sum_file=${1?}