3

I'm trying to run my Spring Boot application in a machine with very limited resources (512M memory), so I need to configure JVM memory settings (Xmx, MaxPermSize etc) to limit consumption and avoid OOM crashes.

I run the app from the command line using Gradle:

gradle bootRun

but I haven't found a way to pass JVM args like -Xmx256m, -XX:MaxPermSize=128M etc. from the command line when starting the app. Any idea anyone?

Nick Melis
  • 403
  • 1
  • 7
  • 19
  • Doesn't these answers work for you? https://stackoverflow.com/questions/25079244/how-to-pass-jvm-options-from-bootrun/26141841 – Infinity Mar 18 '17 at 15:43
  • [ferto31](https://stackoverflow.com/users/12097702) posted an [Answer](https://stackoverflow.com/a/68687768) saying "This other post maybe can help you [Run application via gradlew with -Xmx and -Xms](https://stackoverflow.com/questions/44701947/run-application-via-gradlew-with-xmx-and-xms). or this one [https://gist.github.com/a-r-d/0880779347daedb30f3a72d4903ebe6d](https://gist.github.com/a-r-d/0880779347daedb30f3a72d4903ebe6d) or [How to pass JVM options from bootRun](https://stackoverflow.com/questions/25079244/how-to-pass-jvm-options-from-bootrun)." – Scratte Aug 18 '21 at 06:49

2 Answers2

2

You'd be better of building an executable JAR and then you can pass the java command whatever memory settings you want. Then you can just do:

java -jar -Xmx256m -XX:MaxPermSize=128M .... myApp.jar

Gregg
  • 34,973
  • 19
  • 109
  • 214
  • new to the gradle thing, just needed to `gradle build` and then `java -jar ... ./build/libs/nameOfJar.jar` – Jose V Jun 17 '22 at 06:02
0

You may sse this command in Linux/ Mac:

export _JAVA_OPTIONS="-Xms200m -Xmx800m" 

where values 200 and 400 can be changed as per your needs. Please note its _JAVA_OPTIONS

Then run your gradle command. e.g

gradle bootRun
Ishan Liyanage
  • 2,237
  • 1
  • 26
  • 25