How to install Java application to my linux system

后端 未结 2 694
悲&欢浪女
悲&欢浪女 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
    
    0 讨论(0)
  • 2021-01-25 11:25

    What you did so far is basically "the native" way.

    You have to keep in mind: Java applications are compiled to byte code. There simply is no binary for your application that you could invoke. You do need this detour of calling some JVM installation with a pointer to the main class you want to run. In owhther words; that is what the vast majority of java applications are doing.

    Theoretically, there are products out that there that you could use to actually create a "true" binary from your application; but that isn't an easy path (see here for first starters); and given your statement that your just looking for more "convenience" it is definitely inappropriate here.

    0 讨论(0)
提交回复
热议问题