Skip to content
Advertisement

How to run jar files sequentially from a shell script

I am trying to run two java application one after other in my docker container. In my dockerfile i have specified invoker.sh as the entry point.

ENTRYPOINT ["sh", "/opt/invoker.sh"]

Then i use this script to run two jar files.

#!/bin/sh
java -jar loader.jar
java -jar service.jar

but this does not work. It gives

Error: Unable to access jarfile javaimpl-loader.jar

and only the service.jar is executed. When i tried echo $(ls) it shows that both the jar files are there.

but if i change the script to

#!/bin/sh
echo $(java -jar loader.jar)
java -jar service.jar

then both the jars work. Why cant i use the 1st script. any help regarding this highly apreciated.

Advertisement

Answer

It appears the first example is being treated as a single line, you could work with that. Also, I would prefer bash to /bin/sh. Like,

#!/usr/bin/env bash
java -jar loader.jar && java -jar service.jar
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement