Creating a shell script to run a Java program

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

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

These are my unsuccessful attempts to launch it.

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

if i just do it on the command line it works fine

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

thanks.

+6
java bash shell
source share
2 answers

Use the absolute path to your JAR file, for example. /root/jobs/job.jar . /root/jobs/job.jar .

+3
source share

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

 #!/bin/sh cd `dirname "$0"` java -jar ./job/job.jar 
+7
source share

All Articles