简体   繁体   English

如何设置可执行的Spring Boot jarfile的JVM属性?

[英]How do I set the JVM properties of an executable Spring Boot jarfile?

As a follow-up question to How do I build a Spring Boot jarfile that systemd can execute directly as a service? 作为如何构建Spring Boot jarfile的后续问题,systemd可直接作为服务执行? , how do I set the JVM properties of an executable Spring Boot jarfile? ,如何设置可执行Spring Boot jarfile的JVM属性? For example, how do I set the maximum heap size (ie -Xmx2048m )? 例如,如何设置最大堆大小(即-Xmx2048m )?

Place your-app.conf next to your-app.jar with content 将内容your-app.conf your-app.jar旁边

JAVA_OPTS=-Xmx2048M

Refer to deployment script customization guide or launch.script for details. 有关详细信息,请参考部署脚本定制指南或launch.script

This is not a direct answer to your question, but a way how to work around. 这不是您问题的直接答案,而是解决方法。

I have never opted for an executable jar since I believe it's more flexible to set the parameters from outside at app startup. 我从未选择使用可执行jar,因为我认为在应用程序启动时从外部设置参数会更加灵活。

This is how to set JVM system properties and application properties via command line: 这是通过命令行设置JVM系统属性和应用程序属性的方法:

java -Xmx2048m -jar application.jar --paramname="paramvalue"

You can then get the parameter paramname in a Spring Bean or Service like this: 然后,您可以像这样在Spring Bean或Service中获取参数paramname

@Value("${paramname}")
private String paramname;

You can read more about that topic here: 您可以在此处阅读有关该主题的更多信息:

http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html

Edit 编辑

Take a look at this answer which seems to be what you're looking for: 看一下这个答案,这似乎是您想要的:

https://stackoverflow.com/a/33856394/272180 https://stackoverflow.com/a/33856394/272180

  • According to 1 , one can set JVM properties in environment variable _JAVA_OPTIONS . 根据1 ,可以在环境变量_JAVA_OPTIONS设置JVM属性。
  • According to 2 , environment variable JAVA_TOOL_OPTIONS also sets the JVM properties. 根据2 ,环境变量JAVA_TOOL_OPTIONS也设置JVM属性。

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

相关问题 如何构建一个可以直接作为服务执行的Spring Boot jar文件? - How do I build a Spring Boot jarfile that systemd can execute directly as a service? 如何强制 Spring Boot JVM 进入 UTC 时区? - How do I force a Spring Boot JVM into UTC time zone? 如何在 Spring Boot 应用程序的 application.properties 文件中设置 MyBatis 配置属性? - How do I set MyBatis configuration properties in an application.properties file in a Spring Boot application? 如何从运行时设置Java jvm属性 - How do I set java jvm properties from run time 如何在生产环境中运行 spring boot 可执行 jar? - How do I run a spring boot executable jar in a Production environment? Spring-Boot:如何设置 JDBC 池属性,例如最大连接数? - Spring-Boot: How do I set JDBC pool properties like maximum number of connections? spring 启动:如何动态设置 spring 属性 - spring boot : How to set spring properties dynamically 如果我使用JVM变量设置位置,如何将参数从* .properties设置到SPRING appContext.xml中? - How to set parameter from *.properties into SPRING appContext.xml if i set location with JVM variable? 如何为spring boot创建内部属性文件? - How do I create a internal properties file for spring boot? Spring 启动 maven 插件 - 如何构建可执行 jar 并包含运行它的脚本? - Spring Boot maven plugin - how do I build an executable jar and include a script to run it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM