I want to execute a jar file using java -jar command from a bash script. At the same time I'm passing few parameters which I can access in my main method, using args[].
I'm able to do this without any issues if I try,
java -jar org.sample.jar localhost 8080
but I want to make these parameters configurable through few variables.
Eg:-
HOST=localhost
PORT=8080
When I try to use above variables like following, bash script fails silently.
java -jar org.sample.jar $HOST $PORT
I also tried using "$HOST" but without any luck. What am I doing wrong here?
UPDATE
I was using cygwin to execute/debug my bash script. Once I execute the same script using git bash it works.
You should wrap this in a bash scripts and using bash parameters.
Say you will have a script file sample.sh.
in sample.sh, it contains only one line, which is java -jar org.sample.jar "$@"
Then execute your jar file by bash sample.sh -Host hostname -port 8080
Here is a post about how to do this.
UPDATE
To use variables in your bash script, your script will look like this:
Host="localhost"
Port=8080
java -jar org.sample.jar $Host $Port
I'm using Eclipse and I only wrote one class which has a main method and prints all the arguments. Then I used Eclipse to export a jar file and then used this solution and it worked.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.