1

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 bill_2.pdf

But I want to install the application to my system. So I can just fire up a terminal type in the name of the application and the arguments and hit enter. Like any other "normal" program.

$ analyze bill_1.pdf bill_2.pdf bill_3.pdf

I know I can write a shell script and install it to "/usr/bin/" but I can't believe that there is no "native" way.

So please help, sorry for dump question.

Thank's in advance

  • 1
    Aside from creating your own C-based wrapper or as you mention, a shell script and adding it to the `$PATH` (doesn't necessarily have to be in `/usr/bin`), you can purchase specialized software that does it for you. One of which is [Exe4J](https://www.ej-technologies.com/download/exe4j/files). – Mena Aug 09 '16 at 14:05

2 Answers2

1

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.

Community
  • 1
  • 1
GhostCat
  • 137,827
  • 25
  • 176
  • 248
1

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
apetranzilla
  • 5,331
  • 27
  • 34