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:

<project>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.1.1.RELEASE</version>
                <configuration>
                    <jvmArguments> -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005 </jvmArguments>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

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 -Dspring-boot.run.jvmArguments="-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.