1 回答

TA貢獻1872條經驗 獲得超4個贊
好的,看起來我找到了一些彎曲的方法來完成這一切。
窗戶解決方案:
在 Windows 上捆綁很容易使用launch4j(僅限 Windows)。它是免費的,創建沒有捆綁 Jre 的.exe也沒有問題。
macOS 解決方案:
對于 MacOS,這有點困難:
創建 myApplication.app 文件夾并設計它的結構
編寫啟動器 bash 腳本:在我的情況下,我應該檢測安裝了哪些 Jre 版本并選擇java 1.8和10之間的任何一個
我不知道 bash 腳本語言,我相信我以未優化的方式編寫它。如果有人糾正我,我會很高興。無論如何,它按我想要的方式工作:
#!/bin/sh
# set the working directory
DIR=$(cd "$(dirname "$0")"; pwd)
# extract first fit java version installed
jre_path=$(/usr/libexec/java_home -V 2>&1 |
while IFS= read -r line
do
if [[ "$jre_found" == "true" ]]; then
break
fi
version=$(echo $line | cut -d ' ' -f 1|sed 's/^ *//;s/ *$//' | cut -d ' ' -f 1 | sed 's/^ *//;s/ *$//')
major=$(echo $version | cut -d. -f1)
minor=$(echo $version | cut -d. -f2)
array=(${line// /})
array_size=${#array[@]}
let "last_index=array_size-1"
path=${array[ $last_index ]}
if [[ $major == 1 ]]; then
if [[ $minor -gt 7 && $minor -lt 11 ]]; then
echo $path
jre_found="true"
fi
elif [[ $major -gt 7 && $major -lt 11 ]]; then
echo $path
jre_found="true"
fi
done)
# execute our jar file
$jre_path/bin/java -jar "$DIR"/myApp.jar
現在一切都應該通過雙擊myApplication.app來工作。
添加回答
舉報