Spring boot 运行一个完全可执行的 JAR 并指定 -D 属性 [英] Spring boot running a fully executable JAR and specify -D properties
问题描述
Spring Boot Maven 和 Gradle 插件现在可以为 Linux/Unix 操作系统生成完整的可执行档案.运行一个完全可执行的 JAR 就像输入一样简单:
The Spring Boot Maven and Gradle plugins can now generate full executable archives for Linux/Unix operating systems.Running a fully executable JAR is as easy as typing:
$ ./myapp.jar
我的问题是在这种情况下如何设置 -D 属性,例如
My question is in this case how to set -D properties, e.g.
-Dspring.profiles.active=test
另外,如果服务器没有安装jdk,这个完全可执行的jar还能运行吗?
In addition, if server does not install jdk , could this fully executable jar still run?
推荐答案
有两种方法可以配置这样的属性:
There are two ways to configure properties like that:
1:
通过在单独的配置文件中指定它们.Spring Boot 将查找一个名为 JARfilename.conf
的文件,该文件应与 JAR 文件存储在同一文件夹中.在那里你可以添加环境变量 JAVA_OPTS
:
By specifying them in a separate configuration file. Spring Boot will look for a file named like JARfilename.conf
which should be stored in the same folder like the JAR file. There you can add the environment variable JAVA_OPTS
:
JAVA_OPTS="-Dpropertykey=propvalue"
2:
或者您可以在执行应用程序之前在 shell 中指定环境变量的值:
Or you can just specify the value for the environment variable in the shell before you execute the application:
JAVA_OPTS="-Dpropertykey=propvalue" ./myapp.jar
查看可用变量的完整列表的文档:http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#deployment-service
Have a look at the documentation for the complete list of available variables: http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#deployment-service
关于你的第二个问题:要执行 JAR,你不需要 JDK,一个 JRE 就足够了(但你至少需要那个,如果你没有在服务器上安装任何 java,应用程序将不会't 跑).
Regarding your second question: To execute a JAR, you don't need a JDK, a JRE is sufficient (but you need at least that, if you don't have any java installed on the server, the application won't run).
这篇关于Spring boot 运行一个完全可执行的 JAR 并指定 -D 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!