Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
313 views
in Technique[技术] by (71.8m points)

java - Passing a space-separated System Property via a shell script doesn't work

I have this bash file:

#/bin/bash

PROP="-Dprop=foo bar"

java $PROP -jar Foo.jar

So, what I want to do here is pass a space-separated list as a System Property. But this somehow does not work:

Caused by: java.lang.ClassNotFoundException: bar

So, it seems that Bash breaks -Dprop=foo bar up into -Dprop=foo, bar. I tried everything from double quoting to escaping the space character but nothing seems to work.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to add the quotation marks around the shell script $ variable:

PROP="-Dprop=foo bar"

java "$PROP" -jar Foo.jar

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...