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来工作。
添加回答
举报