0

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

4
  • From a shell-script I guess. Commented Nov 30, 2016 at 16:37
  • Is that the only way? Commented Nov 30, 2016 at 16:40
  • see this stackoverflow.com/questions/23072187/… Commented Nov 30, 2016 at 16:42
  • @Saravana, that question doesn't apply because my application doesn't use embedded Tomcat. Commented Nov 30, 2016 at 16:48

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

0
  • 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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.