Derek Mahar
Derek Mahar

Reputation: 28386

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?, how do I set the JVM properties of an executable Spring Boot jarfile? For example, how do I set the maximum heap size (i.e. -Xmx2048m)?

Upvotes: 0

Views: 4907

Answers (3)

yglodt
yglodt

Reputation: 14551

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.

This is how to set JVM system properties and application properties via command line:

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

You can then get the parameter paramname in a Spring Bean or Service like this:

@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

Edit

Take a look at this answer which seems to be what you're looking for:

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

Upvotes: 1

tan9
tan9

Reputation: 3620

Place your-app.conf next to your-app.jar with content

JAVA_OPTS=-Xmx2048M

Refer to deployment script customization guide or launch.script for details.

Upvotes: 2

Derek Mahar
Derek Mahar

Reputation: 28386

  • According to 1, one can set JVM properties in environment variable _JAVA_OPTIONS.
  • According to 2, environment variable JAVA_TOOL_OPTIONS also sets the JVM properties.

Upvotes: 0

Related Questions