diff --git a/forge-adventure/src/main/config/forge-adventure-editor-mac.sh b/forge-adventure/src/main/config/forge-adventure-editor-mac.sh index eb3d4f9adb7..ed86f0b6514 100644 --- a/forge-adventure/src/main/config/forge-adventure-editor-mac.sh +++ b/forge-adventure/src/main/config/forge-adventure-editor-mac.sh @@ -1,3 +1,4 @@ #!/bin/sh cd $(dirname "${0}") -java -XstartOnFirstThread -Xmx4096m -Dfile.encoding=UTF-8 -jar $project.build.finalName$ +java="${JAVA_HOME:+$JAVA_HOME/bin/}java" +$java -XstartOnFirstThread -Xmx4096m -Dfile.encoding=UTF-8 -jar $project.build.finalName$ diff --git a/forge-adventure/src/main/config/forge-adventure-editor.sh b/forge-adventure/src/main/config/forge-adventure-editor.sh index 1e3165f2ed0..f19a81b1727 100644 --- a/forge-adventure/src/main/config/forge-adventure-editor.sh +++ b/forge-adventure/src/main/config/forge-adventure-editor.sh @@ -1,3 +1,4 @@ #!/bin/sh cd $(dirname "${0}") -java -Xmx4096m -Dfile.encoding=UTF-8 -jar $project.build.finalName$ +java="${JAVA_HOME:+$JAVA_HOME/bin/}java" +$java -Xmx4096m -Dfile.encoding=UTF-8 -jar $project.build.finalName$ diff --git a/forge-gui-desktop/src/main/config/forge.sh b/forge-gui-desktop/src/main/config/forge.sh index 8d53f38d841..3875c0c090c 100644 --- a/forge-gui-desktop/src/main/config/forge.sh +++ b/forge-gui-desktop/src/main/config/forge.sh @@ -1,21 +1,13 @@ #!/bin/bash - + # returns the JDK version. # 8 for 1.8.0_nn, 9 for 9-ea etc, and "no_java" for undetected # Based on the code from this source: https://eed3si9n.com/detecting-java-version-bash jdk_version() { local result - local java_cmd - if [[ -n $(type -p java) ]] - then - java_cmd=java - elif [[ (-n "$JAVA_HOME") && (-x "$JAVA_HOME/bin/java") ]] - then - java_cmd="$JAVA_HOME/bin/java" - fi - local IFS=$'\n' + local IFS; IFS=$'\n' # remove \r for Cygwin - local lines=$("$java_cmd" -Xms32M -Xmx32M -version 2>&1 | tr '\r' '\n') + local lines; lines="$("$java_cmd" -Xms32M -Xmx32M -version 2>&1 | tr '\r' '\n')" if [[ -z $java_cmd ]] then result=no_java @@ -23,30 +15,38 @@ jdk_version() { for line in $lines; do if [[ (-z $result) && ($line = *"version \""*) ]] then - local ver=$(echo $line | sed -e 's/.*version "\(.*\)"\(.*\)/\1/; 1q') + local ver; ver=$(echo "$line" | sed -e 's/.*version "\(.*\)"\(.*\)/\1/; 1q') # on macOS, sed doesn't support '?' if [[ $ver = "1."* ]] then - result=$(echo $ver | sed -e 's/1\.\([0-9]*\)\(.*\)/\1/; 1q') + result=$(echo "$ver" | sed -e 's/1\.\([0-9]*\)\(.*\)/\1/; 1q') else - result=$(echo $ver | sed -e 's/\([0-9]*\)\(.*\)/\1/; 1q') + result=$(echo "$ver" | sed -e 's/\([0-9]*\)\(.*\)/\1/; 1q') fi fi done fi echo "$result" } + +if [[ (-n "$JAVA_HOME") && (-x "$JAVA_HOME/bin/java") ]] +then + java_cmd="$JAVA_HOME/bin/java" +elif [[ -n $(type -p java) ]] +then + java_cmd="java" +fi v="$(jdk_version)" SHAREDPARAMS='-Xmx4096m -Dfile.encoding=UTF-8 -jar $project.build.finalName$ '"$@" -cd $(dirname "${0}") +cd "$(dirname "${0}")" || exit if [[ $v -ge 17 ]] then - java --add-opens java.desktop/java.beans=ALL-UNNAMED --add-opens java.desktop/java.awt.color=ALL-UNNAMED --add-opens java.desktop/javax.swing.border=ALL-UNNAMED --add-opens java.desktop/javax.swing.event=ALL-UNNAMED --add-opens java.desktop/sun.awt.image=ALL-UNNAMED --add-opens java.desktop/sun.swing=ALL-UNNAMED --add-opens java.desktop/javax.swing=ALL-UNNAMED --add-opens java.desktop/java.awt=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.text=ALL-UNNAMED --add-opens java.desktop/java.awt.font=ALL-UNNAMED --add-opens java.desktop/java.awt.image=ALL-UNNAMED --add-opens java.base/jdk.internal.misc=ALL-UNNAMED --add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/java.math=ALL-UNNAMED --add-opens java.base/java.util.concurrent=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED -Dio.netty.tryReflectionSetAccessible=true $SHAREDPARAMS + $java_cmd --add-opens java.desktop/java.beans=ALL-UNNAMED --add-opens java.desktop/java.awt.color=ALL-UNNAMED --add-opens java.desktop/javax.swing.border=ALL-UNNAMED --add-opens java.desktop/javax.swing.event=ALL-UNNAMED --add-opens java.desktop/sun.awt.image=ALL-UNNAMED --add-opens java.desktop/sun.swing=ALL-UNNAMED --add-opens java.desktop/javax.swing=ALL-UNNAMED --add-opens java.desktop/java.awt=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.text=ALL-UNNAMED --add-opens java.desktop/java.awt.font=ALL-UNNAMED --add-opens java.desktop/java.awt.image=ALL-UNNAMED --add-opens java.base/jdk.internal.misc=ALL-UNNAMED --add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/java.math=ALL-UNNAMED --add-opens java.base/java.util.concurrent=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED -Dio.netty.tryReflectionSetAccessible=true $SHAREDPARAMS elif [[ $v -ge 11 ]] then - java --illegal-access=permit $SHAREDPARAMS + $java_cmd --illegal-access=permit $SHAREDPARAMS else - java $SHAREDPARAMS + $java_cmd $SHAREDPARAMS fi diff --git a/forge-gui-mobile-dev/src/main/config/forge-adventure-mac.sh b/forge-gui-mobile-dev/src/main/config/forge-adventure-mac.sh index 6d208042fee..66382d0c3fe 100644 --- a/forge-gui-mobile-dev/src/main/config/forge-adventure-mac.sh +++ b/forge-gui-mobile-dev/src/main/config/forge-adventure-mac.sh @@ -1,3 +1,4 @@ #!/bin/sh cd $(dirname "${0}") -java -XstartOnFirstThread -Xmx4096m --add-opens java.desktop/java.beans=ALL-UNNAMED --add-opens java.desktop/javax.swing.border=ALL-UNNAMED --add-opens java.desktop/javax.swing.event=ALL-UNNAMED --add-opens java.desktop/sun.swing=ALL-UNNAMED --add-opens java.desktop/java.awt.image=ALL-UNNAMED --add-opens java.desktop/java.awt.color=ALL-UNNAMED --add-opens java.desktop/sun.awt.image=ALL-UNNAMED --add-opens java.desktop/javax.swing=ALL-UNNAMED --add-opens java.desktop/java.awt=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.text=ALL-UNNAMED --add-opens java.desktop/java.awt.font=ALL-UNNAMED --add-opens java.base/jdk.internal.misc=ALL-UNNAMED --add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/java.math=ALL-UNNAMED --add-opens java.base/java.util.concurrent=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED -Dio.netty.tryReflectionSetAccessible=true -Dfile.encoding=UTF-8 -jar $project.build.finalName$ +java="${JAVA_HOME:+$JAVA_HOME/bin/}java" +$java -XstartOnFirstThread -Xmx4096m --add-opens java.desktop/java.beans=ALL-UNNAMED --add-opens java.desktop/javax.swing.border=ALL-UNNAMED --add-opens java.desktop/javax.swing.event=ALL-UNNAMED --add-opens java.desktop/sun.swing=ALL-UNNAMED --add-opens java.desktop/java.awt.image=ALL-UNNAMED --add-opens java.desktop/java.awt.color=ALL-UNNAMED --add-opens java.desktop/sun.awt.image=ALL-UNNAMED --add-opens java.desktop/javax.swing=ALL-UNNAMED --add-opens java.desktop/java.awt=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.text=ALL-UNNAMED --add-opens java.desktop/java.awt.font=ALL-UNNAMED --add-opens java.base/jdk.internal.misc=ALL-UNNAMED --add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/java.math=ALL-UNNAMED --add-opens java.base/java.util.concurrent=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED -Dio.netty.tryReflectionSetAccessible=true -Dfile.encoding=UTF-8 -jar $project.build.finalName$ diff --git a/forge-gui-mobile-dev/src/main/config/forge-adventure.sh b/forge-gui-mobile-dev/src/main/config/forge-adventure.sh index 575b5a5b090..c1eaff1a66f 100644 --- a/forge-gui-mobile-dev/src/main/config/forge-adventure.sh +++ b/forge-gui-mobile-dev/src/main/config/forge-adventure.sh @@ -1,3 +1,4 @@ #!/bin/sh cd $(dirname "${0}") -java -Xmx4096m --add-opens java.desktop/java.beans=ALL-UNNAMED --add-opens java.desktop/javax.swing.border=ALL-UNNAMED --add-opens java.desktop/javax.swing.event=ALL-UNNAMED --add-opens java.desktop/sun.swing=ALL-UNNAMED --add-opens java.desktop/java.awt.image=ALL-UNNAMED --add-opens java.desktop/java.awt.color=ALL-UNNAMED --add-opens java.desktop/sun.awt.image=ALL-UNNAMED --add-opens java.desktop/javax.swing=ALL-UNNAMED --add-opens java.desktop/java.awt=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.text=ALL-UNNAMED --add-opens java.desktop/java.awt.font=ALL-UNNAMED --add-opens java.base/jdk.internal.misc=ALL-UNNAMED --add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/java.math=ALL-UNNAMED --add-opens java.base/java.util.concurrent=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED -Dio.netty.tryReflectionSetAccessible=true -Dfile.encoding=UTF-8 -jar $project.build.finalName$ +java="${JAVA_HOME:+$JAVA_HOME/bin/}java" +$java -Xmx4096m --add-opens java.desktop/java.beans=ALL-UNNAMED --add-opens java.desktop/javax.swing.border=ALL-UNNAMED --add-opens java.desktop/javax.swing.event=ALL-UNNAMED --add-opens java.desktop/sun.swing=ALL-UNNAMED --add-opens java.desktop/java.awt.image=ALL-UNNAMED --add-opens java.desktop/java.awt.color=ALL-UNNAMED --add-opens java.desktop/sun.awt.image=ALL-UNNAMED --add-opens java.desktop/javax.swing=ALL-UNNAMED --add-opens java.desktop/java.awt=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.text=ALL-UNNAMED --add-opens java.desktop/java.awt.font=ALL-UNNAMED --add-opens java.base/jdk.internal.misc=ALL-UNNAMED --add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/java.math=ALL-UNNAMED --add-opens java.base/java.util.concurrent=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED -Dio.netty.tryReflectionSetAccessible=true -Dfile.encoding=UTF-8 -jar $project.build.finalName$