且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Spring boot 运行一个完全可执行的 JAR 并指定 -D 属性

更新时间:2023-09-29 22:23:58

有两种方法可以配置这样的属性:

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).