像 shell一样执行 jar

前端之家收集整理的这篇文章主要介绍了像 shell一样执行 jar前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

一.新建 stub.sh

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

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

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

三. 执行

  1. ./helloworld

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

猜你在找的Bash相关文章