英文:
pass environment variable to jar as command line arguments
问题
我正在运行一个读取代码中属性的JAR文件。现在我想在环境级别上设置一些变量,并将它们作为命令行参数传递以覆盖这些属性。我该如何做到这一点?
示例:
java -jar test.jar --server.http.host-url=https://x.com
在上述命令中,属性值server.http.host-url
被设置为环境变量,名称为server.http.host.value
。我如何将它作为变量传递,以便它将从环境变量中解析,就像这样:
java -jar test.jar --server.http.host-url=${server.http.host.value}
英文:
I am running a jar which reads from properties in code. Now i want to set few variables at environment level and pass them as command line arguments to override properties. How can i do that?
ex:
java -jar test.jar --server.http.host-url=https://x.com
in the above command, property value server.http.host-url is set as env variable with name "server.http.host.value". how do i pass it as variable so it will resolved from env variables like this
java -jar test.jar --server.http.host-url=${server.http.host.value}
答案1
得分: 4
根据您使用的 shell 不同,环境变量的名称可能会有不同的限制,但在大多数情况下,.
是不允许的,因此请将您的变量命名为类似 SERVER_HTTP_HOST_VALUE
的形式,并像这样使用它:
java -jar test.jar --server.http.host-url=$SERVER_HTTP_HOST_VALUE
英文:
Depending on the shell you are using the environment variable names might have different restrictions, but in most cases .
is not allowed so name your variable something like SERVER_HTTP_HOST_VALUE
for example and use it like this:
java -jar test.jar --server.http.host-url=$SERVER_HTTP_HOST_VALUE
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论