7

I have created a shell script to run a jar file in Mac :

#!/bin/sh java -Xmx512m -jar test.jar; 

I have renamed this script "app.command" to run directly when double clicking it. And i have applied "chmod +x" command to it to have executable permissions.

Now when double clicking this script, i get "Unable to access jarfile test.jar" while when running this script through Terminal, the jar runs fine !

Anyone can help me how to make this script run when double click it in Mac ?

1 Answer 1

8

If you run from a terminal, you have a working directory set, and this may not be the case if you double-click it. Try giving the full path to the jarfile in your script.

Sign up to request clarification or add additional context in comments.

6 Comments

@Curtis: You are right. But is there a way to overcome this ? The jar can be anywhere, but i am sure the shell script will be in the same folder of the jar file ?
Okay ... I guess the question now is : "Can i get the absolute path of the current running shell script & use it ?"
This can get arbitrarily complicated, but if the script is run by double-clicking (and isn't a symbolic link), cd "$(dirname "$0")" should work.
@Gordon ... Thanks a lot .. So how would i use this in my script ? :) ... I know nothing about shell scripting. Example please ?
Add this command as the second line of the script (i.e. right after #!/bin/sh -- that way the rest of the script (mainly the java command) will execute from within the script's directory.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.