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.

codaddict
457k83 gold badges503 silver badges538 bronze badges
asked Aug 30, 2010 at 7:40
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
answered Aug 30, 2010 at 7:50
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.

answered Aug 30, 2010 at 7:46

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.