How to set JVM settings in a Spring Boot application

The simplest way to set JVM settings in a Spring Boot application is to execute the jar file and passing the JVM settings as in the following example:

$ java -Xmx32m -Xss256k -jar target/demo-app-SNAPSHOT.jar

Another option is to set JVM arguments in the spring-boot-maven-plugin:

For example, the following configuration suspend the process until a debugger has joined on port 5005:

                    <jvmArguments> -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005 </jvmArguments>

Note that since you specified some JVM arguments, the process is forked automatically. These arguments can be specified on the command line as well, make sure to wrap that properly, that is:

mvn spring-boot:run"-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"

Finally, another option consists in dropping a .conf file in the same directory as your WAR that is effectively a shell script:

$ ls demoapp.conf myapp.war 
$ cat demoapp.conf 
export JAVA_OPTS="-Xmx2048m -Xms256m"

Any configuration you do there will be run before the Spring Boot embedded Tomcat starts up.