Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a shell script to run Java program

Tags:

java

bash

shell

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.

like image 615
Sameek Mishra Avatar asked Aug 30 '10 07:08

Sameek Mishra


1 Answers

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
like image 116
Colin Hebert Avatar answered Sep 23 '22 04:09

Colin Hebert