简体   繁体   English

Spring Boot可执行文件JAVA_OPTS用空格覆盖

[英]Spring Boot executable JAVA_OPTS override with spaces

I'm using Spring Boot 1.4.1 to create an executable Unix JAR file (per the instructions here ). 我正在使用Spring Boot 1.4.1创建一个可执行的Unix JAR文件(按照此处的说明)。 I'm using a custom .conf file to set the JAVA_OPTS value at run-time. 我正在使用自定义.conf文件在运行时设置JAVA_OPTS值。 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" 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). 现在,我想覆盖已在application.yml文件(嵌入在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" JAVA_OPTS =“-Dmy.param =一个两个-Dspring.profiles.active =产品-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" JAVA_OPTS =“-Dmy.param =一个\\两个-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 JAVA_OPTS = -Dmy.param =一个\\两个-Dspring.profiles.active = prod -Dflyway.validate-on-migrate = false -Djavax.net.ssl.trustStore = / var / myapp / truststore.jks -Djavax.net。 ssl.trustStorePassword =更改

...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" JAVA_OPTS =“”-Dmy.param =一个\\两个“ -Dspring.profiles.active =产品-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 错误:找不到或加载主类2

...or... ...要么...

/var/myapp/myapp.conf line 1: Two: command not found /var/myapp/myapp.conf第1行:两个:找不到命令

I've looked inside the code that's embedded in the top of the JAR file and it seems to be: 我查看了嵌入在JAR文件顶部的代码,里面似乎是:

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值时遇到麻烦

遇到相同的问题,发现用反斜杠转义嵌入式双引号确实可以解决问题,如下所示:

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 . 我最终要做的是按照此处的说明使用外部化的application.yml Still not exactly what I wanted, but it'll do for now. 仍然不是我想要的,但是现在就可以了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM