I'm using Spring Boot 1.4.1 to create an executable Unix JAR file (per the instructions here ). I'm using a custom .conf file to set the JAVA_OPTS
value at run-time. This has been working fine with the following contents:
JAVA_OPTS="-Dspring.profiles.active=prod -Dflyway.validate-on-migrate=false -Djavax.net.ssl.trustStore=/var/myapp/truststore.jks -Djavax.net.ssl.trustStorePassword=changeit"
I now want to override a parameter that I've got configured in my application.yml file (that's embedded within the JAR). The problem is that the values of this parameter have spaces in them.
I've tried:
JAVA_OPTS="-Dmy.param=One Two -Dspring.profiles.active=prod -Dflyway.validate-on-migrate=false -Djavax.net.ssl.trustStore=/var/myapp/truststore.jks -Djavax.net.ssl.trustStorePassword=changeit"
...and...
JAVA_OPTS="-Dmy.param=One\\ Two -Dspring.profiles.active=prod -Dflyway.validate-on-migrate=false -Djavax.net.ssl.trustStore=/var/myapp/truststore.jks -Djavax.net.ssl.trustStorePassword=changeit"
...and...
JAVA_OPTS=-Dmy.param=One\\ Two -Dspring.profiles.active=prod -Dflyway.validate-on-migrate=false -Djavax.net.ssl.trustStore=/var/myapp/truststore.jks -Djavax.net.ssl.trustStorePassword=changeit
...and...
JAVA_OPTS=""-Dmy.param=One\\ Two" -Dspring.profiles.active=prod -Dflyway.validate-on-migrate=false -Djavax.net.ssl.trustStore=/var/myapp/truststore.jks -Djavax.net.ssl.trustStorePassword=changeit"
But I get various error messages like:
Error: Could not find or load main class Two
...or...
/var/myapp/myapp.conf line 1: Two: command not found
I've looked inside the code that's embedded in the top of the JAR file and it seems to be:
arguments=(-Dsun.misc.URLClassPath.disableJarChecking=true $JAVA_OPTS -jar $jarfile $RUN_ARGS "$@")
...but I'm having trouble working out how to translate this into a JAVA_OPTS value that works
遇到相同的问题,发现用反斜杠转义嵌入式双引号确实可以解决问题,如下所示:
JAVA_OPTS="-Dmy.param=\"One Two\" -Dspring.profiles.active=prod -Dflyway.validate-on-migrate=false -Djavax.net.ssl.trustStore=/var/myapp/truststore.jks -Djavax.net.ssl.trustStorePassword=changeit"
What I ended up doing was using an externalised application.yml
per the instructions here . Still not exactly what I wanted, but it'll do for now.
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.