How to install Java application to my linux system

后端 未结 2 718
悲&欢浪女
悲&欢浪女 2021-01-25 11:00

I have written a Java application that analyzes my phone bills and calculates the average. At the moment I execute it like:

$ java -jar analyze.jar bill_1.pdf bi         


        
2条回答
  •  长发绾君心
    2021-01-25 11:12

    One neat little trick is that you can append a basic shell script to the start of the jar file which will run it appropriately. See here for the full example but the basics are:

    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
    

    Then do...

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

    And you should be all set! Now you can just call the script-ified jar directly.

    ./helloworld.run
    

提交回复
热议问题