6

I used a shell script to run a Java class. My script contains

#!/bin/sh
java -jar jobs/job.jar

These are my failed attempts to run it.

[root@]#sh testapp.sh
Unable to access jarfile jobs/job.jar

if I just do this at the command line it works fine

[root@]#java -jar jobs/job.jar

thanks.

2
  • 1
    Do you run the script from the same directory ? Commented Aug 30, 2010 at 7:43
  • It is not recommended to routinely run things in super user mode (aka root). Commented Aug 30, 2010 at 7:57

2 Answers 2

7

The best way is to get the current dirname and get in there with this:

#!/bin/sh
cd `dirname "$0"`
java -jar ./job/job.jar
Sign up to request clarification or add additional context in comments.

1 Comment

This seems like the actual right answer, because using an absolute path is not an option when you plan to move the files (or even share it)
3

Use the absolute path to your JAR file, e. g. /root/jobs/job.jar.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.