加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

像 shell一样执行 jar

发布时间:2020-12-15 09:09:37 所属栏目:安全 来源:网络整理
导读:像 shell一样执行 jar 通常执行 java -jar helloworld.jar 可是看到 kettle 执行时候 ./spoon 或者 presto客户端 执行时候 ./presto 执行很间洁,怎么做到的? 一.新建 stub.sh #!/bin/sh MYSELF=`which " $0 " 2 /dev/null`[ $? -gt 0 -a -f " $0 " ] MYSEL

像 shell一样执行 jar
通常执行 java -jar helloworld.jar
可是看到 kettle 执行时候 ./spoon 或者 presto客户端 执行时候 ./presto
执行很间洁,怎么做到的?

一.新建 stub.sh

#!/bin/sh
MYSELF=`which "$0" 2>/dev/null`
[ $? -gt 0 -a -f "$0" ] && MYSELF="./$0"
java=java
if test -n "$JAVA_HOME"; then
    java="$JAVA_HOME/bin/java"
fi
exec "$java" $java_args -jar $MYSELF "$@"
exit 1

二. 将脚本和 jar 合并,并赋予权限

cat stub.sh helloworld.jar > helloworld && chmod +x helloworld

三. 执行

./helloworld

参考文章: https://coderwall.com/p/ssuaxa/how-to-make-a-jar-file-linux-executable

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读