0

I'd like to add -Xmx6g as a command line argument to a spring boot application that is launched with maven via mvn spring-boot:run. I do this easily enough with Intellij, but I would like to launch the application manually from my terminal so that I have some extra ram.

I've tried to configure in the Maven Surefire Plugin, but this hasn't worked. Could anyone share a working snippit?

Danubian Sailor
  • 1
  • 38
  • 145
  • 223
MrUwugu
  • 56
  • 3
  • The [Spring docs](https://docs.spring.io/spring-boot/docs/2.7.x/reference/htmlsingle/#using.running-your-application.with-the-maven-plugin) suggest to set those via [`MAVEN_OPTS`](https://maven.apache.org/configure.html#maven_opts-environment-variable), e.g. `export MAVEN_OPTS=-Xmx6g` - does that help? – Christian Jun 02 '22 at 21:17
  • Alternatively [`jvmArguments`](https://docs.spring.io/spring-boot/docs/2.2.2.RELEASE/maven-plugin/run-mojo.html#jvmArguments) ([current docs](https://docs.spring.io/spring-boot/docs/2.7.x/maven-plugin/reference/htmlsingle/#run)) as per https://stackoverflow.com/a/68069089/2018047 – Christian Jun 02 '22 at 21:24
  • 1
    @Christian: in the documentation you've provided, I'm confused as to why an example cannot be provided. Firstly, I imagine such a command might look like mvn spring-boot:run jvmArguments="-Xmx6g" but, this isn't explicitly stated anywhere. What's worse is that the documentation also says "NOTE: [something important about needing a forked process", and I have a feeling that I would also need an example of how to specify that I would like to launch with a forked process. This is a bit tedious compared to how this works in the java command line, so I think asking for an example is ok. – MrUwugu Jun 02 '22 at 22:30
  • The reason I haven't given you an example is that I never used that option myself, so I'm just not sure. I imagine people who configure a JVM on servers understand the docs without needing additional examples (and it would be a long list if they provided an example for every possible argument). The way I read the docs, it forks automatically (unless you explicitly specify `fork` as `false`, which is deprecated). To try it locally, I'd use `$ mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Xmx6G"`. Also consider [`-XX:+PrintFlagsFinal`](https://stackoverflow.com/a/22108304/2018047) 2 check – Christian Jun 05 '22 at 11:40
  • An [example for how to use the jvmArguments](https://docs.spring.io/spring-boot/docs/2.7.x/maven-plugin/reference/htmlsingle/#run.examples.debug) is actually provided, albeit under the "debug" heading. Also, if it works in IntelliJ: you can usually expand the command that IntelliJ used to launch an app in the console tab IntelliJ opens. Surefire is a plugin to run tests, so if you want to increase memory while testing, you'd likely have to use a different argument. [`argLine`](https://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html#argLine) might work. – Christian Jun 05 '22 at 11:48
  • @Christian appreciated, I will try this and will return back if it works :) – MrUwugu Jun 06 '22 at 16:50

0 Answers0