Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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
share|improve this question

2 Answers

up vote 1 down vote accepted

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.

share|improve this answer
changing to the directory and then running the java -jar start.jar worked, much thanks! – c12 Mar 13 '12 at 3:44

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.