0

So I have made this simple java app which I want to run with a simple double-click that opens my terminal and run the code on a Mac.

I written a simple start.sh script like this

#!/bin/sh
java -jar monkeykingApplication.jar

But this gives me and error because the jar can not be located. So what path do I need to set if run my start.sh script in the same folder as my jar file is?

1 Answers1

0

Your example uses sh as shell, but you are tagging your question as bash, so I take the liberty to propose a bash solution:

Since you are delivering your jar together with a bash starter script, I would require that the starter script and the jar be installed by the user in the same directory. In your starter script, you can then find your own location, and use this information to locate the jar. How to find this location, has been discussed here. Using one of the answers in that page, you could do a:

#!/bin/bash
# Find your own location
install_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# Invoke the jar
java -jar "$install_dir/monkeykingApplication.jar"

Most likely, the user will add the directory of the starter script to their PATH variable, but this is his/her own decision, and you don't have to care about this.

user1934428
  • 19,864
  • 7
  • 42
  • 87