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
Sameek Mishra
9,43431 gold badges96 silver badges118 bronze badges
-
1Do you run the script from the same directory ?Cedric H.– Cedric H.2010年08月30日 07:43:58 +00:00Commented Aug 30, 2010 at 7:43
-
It is not recommended to routinely run things in super user mode (aka root).emory– emory2010年08月30日 07:57:50 +00:00Commented Aug 30, 2010 at 7:57
2 Answers 2
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
Colin Hebert
93.5k16 gold badges164 silver badges154 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Sloy
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)
Use the absolute path to your JAR file, e. g. /root/jobs/job.jar.
answered Aug 30, 2010 at 7:46
joschi
13.1k4 gold badges47 silver badges51 bronze badges
Comments
default