c12
c12

Reputation: 9827

Unix Shell Scripting and Java Jar Command

I have a Unix shell script (bash) that sources some environment variables and then gives the user a few options. Based on the user input I call some other Unix shell scripts that perform certain actions. I'm having an issue with the start app server option below. When I execute the appserver/run.sh script from main.sh I get a "Unable to access jarfile start.jar". When I navigate directly to the run.sh script and run it from its directory, it works. start.jar starts up a Jetty application server. Any ideas on how to execute run.sh from main.sh?

permissions:

-rw-r--r--  1 colgray eng  42364 Jan 10 15:40 start.jar

main.sh:

source ./setupenvironment.sh
echo "Which Example would you like to run?"
select yn in "one" "two" "start app server" "Quit" do
    case $yn in
        "one" ) ./examples/one/scripts/one.sh; break;;
        "two" ) ./examples/twp/scripts/two.sh; break;;
        **"start app server" ) ./examples/appserver/run.sh; break;;**
         Quit ) exit;;
    esac
done

/examples/appserver/run.sh:

java -jar start.jar

Upvotes: 0

Views: 3075

Answers (2)

paxdiablo
paxdiablo

Reputation: 881363

Since you're running from a directory other than ./examples/appserver, it cannot find your jar file:

<somewhere>                        <-- this is where you are
     |                                  ^
     +--> examples                      | <- this is a distance too far :-)
             |                          v
             +--> appserver        <- this is where start.jar is

Based on the fact that you seem to be running it from the directory where examples lives (otherwise the relative paths wouldn't work), you'll need either

java -jar examples/appserver/start.jar

or:

cd examples/appserver
java -jar start.jar

in your run.sh file.

Upvotes: 1

blahdiblah
blahdiblah

Reputation: 33991

Change run.sh to use an absolute path to start.jar.

Upvotes: 0

Related Questions