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)?
-
From a shell-script I guess.kometen– kometen2016-11-30 16:37:03 +00:00Commented Nov 30, 2016 at 16:37
-
Is that the only way?Derek Mahar– Derek Mahar2016-11-30 16:40:24 +00:00Commented Nov 30, 2016 at 16:40
-
see this stackoverflow.com/questions/23072187/…Saravana– Saravana2016-11-30 16:42:15 +00:00Commented Nov 30, 2016 at 16:42
-
@Saravana, that question doesn't apply because my application doesn't use embedded Tomcat.Derek Mahar– Derek Mahar2016-11-30 16:48:05 +00:00Commented Nov 30, 2016 at 16:48
3 Answers
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.
Comments
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: