Sameek Mishra
Sameek Mishra

Reputation: 9404

Creating a shell script to run 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 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.

Upvotes: 6

Views: 20392

Answers (2)

Colin Hebert
Colin Hebert

Reputation: 93187

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

Upvotes: 7

joschi
joschi

Reputation: 13101

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

Upvotes: 3

Related Questions