title: spring boot maven plugin - jvm arguments - direct memory size setting
body: <p>I am using <strong>spring-boot-maven-plugin</strong> to build a docker image from my app with this command:</p>
  <pre><code>spring-boot::build-image
  </code></pre>
  <p>And I need to change default size of jvm direct memory (default is 10m) with this jvm argument:</p>
  <pre><code>-XX:MaxDirectMemorySize=64M
  </code></pre>
  <p>and this is my desperate attempt to do that in <code>pom.xml</code> of app where I was trying everything what came to my mind:</p>
  <pre><code>&lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;configuration&gt;
                              &lt;jvmArguments&gt;-XX:MaxDirectMemorySize=64M&lt;/jvmArguments&gt;
                              &lt;environmentVariables&gt;
                                  &lt;JAVA_TOOL_OPTIONS&gt;-XX:MaxDirectMemorySize=64M&lt;/JAVA_TOOL_OPTIONS&gt;
                                  &lt;JAVA_OPTS&gt;-XX:MaxDirectMemorySize=64M&lt;/JAVA_OPTS&gt;
                              &lt;/environmentVariables&gt;
                              &lt;systemPropertyVariables&gt;
                                  &lt;JAVA_TOOL_OPTIONS&gt;-XX:MaxDirectMemorySize=64M&lt;/JAVA_TOOL_OPTIONS&gt;
                                  &lt;JAVA_OPTS&gt;-XX:MaxDirectMemorySize=64M&lt;/JAVA_OPTS&gt;
                              &lt;/systemPropertyVariables&gt;
                          &lt;/configuration&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
  
                  &lt;configuration&gt;
                      &lt;layers&gt;
                          &lt;enabled&gt;true&lt;/enabled&gt;
                      &lt;/layers&gt;
                      &lt;image&gt;
                          &lt;name&gt;docker.io/example/${project.artifactId}:${project.version}&lt;/name&gt;
                      &lt;/image&gt;
  
                      &lt;excludeDevtools&gt;true&lt;/excludeDevtools&gt;
  
                      &lt;systemPropertyVariables&gt;
                          &lt;JAVA_TOOL_OPTIONS&gt;-XX:MaxDirectMemorySize=64M&lt;/JAVA_TOOL_OPTIONS&gt;
                          &lt;JAVA_OPTS&gt;-XX:MaxDirectMemorySize=64M&lt;/JAVA_OPTS&gt;
                      &lt;/systemPropertyVariables&gt;
                      &lt;environmentVariables&gt;
                          &lt;JAVA_TOOL_OPTIONS&gt;-XX:MaxDirectMemorySize=64M&lt;/JAVA_TOOL_OPTIONS&gt;
                          &lt;JAVA_OPTS&gt;-XX:MaxDirectMemorySize=64M&lt;/JAVA_OPTS&gt;
                      &lt;/environmentVariables&gt;
                      &lt;jvmArguments&gt;-XX:MaxDirectMemorySize=64M -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005&lt;/jvmArguments&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
  </code></pre>
  <p>But direct memory is still setup to 10M :(
  which I can see in log file when the app is booting up:</p>
  <pre><code>Picked up JAVA_TOOL_OPTIONS: -Djava.security.properties=/layers/paketo-buildpacks_bellsoft-liberica/java-security-properties/java-security.properties -agentpath:/layers/paketo-buildpacks_bellsoft-liberica/jvmkill/jvmkill-1.16.0-RELEASE.so=printHeapHistogram=1 -XX:ActiveProcessorCount=8 -XX:MaxDirectMemorySize=10M -Xmx11521920K -XX:MaxMetaspaceSize=144375K -XX:ReservedCodeCacheSize=240M -Xss1M -Dorg.springframework.cloud.bindings.boot.enable=true
  </code></pre>
  <p>Can anybody advise me what Am I doing wrong?</p>
  <p>NOTES:</p>
  <p>Spring Boot: 2.3.7.RELEASE</p>
  <p>when I run docker image manually with <code>-e</code>, change of jvm argument is working:</p>
  <pre><code>docker run -e JAVA_TOOL_OPTIONS=-XX:MaxDirectMemorySize=64M  docker.io/example/app-name:0.0.1
  </code></pre>
  <p>this mvn plugin is using Buildpack to create the docker image:</p>
  <p><a href="https://paketo.io/docs/buildpacks/language-family-buildpacks/java/#about-the-jvm" rel="nofollow noreferrer">https://paketo.io/docs/buildpacks/language-family-buildpacks/java/#about-the-jvm</a></p>
  <p>UPDATE:</p>
  <p>by the doc this should be working solution but it is not:</p>
  <pre><code>            &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
                  &lt;configuration&gt;
                      &lt;layers&gt;
                          &lt;enabled&gt;true&lt;/enabled&gt;
                      &lt;/layers&gt;
                      &lt;image&gt;
                          &lt;name&gt;docker.io/example/${project.artifactId}:${project.version}&lt;/name&gt;
                          &lt;env&gt;
                              &lt;JAVA_TOOL_OPTIONS&gt;-XX:MaxDirectMemorySize=64M&lt;/JAVA_TOOL_OPTIONS&gt;
                          &lt;/env&gt;
                      &lt;/image&gt;
                  &lt;/configuration&gt;
  </code></pre>