My application does large data arrays processing and needs more memory than JVM gives by default. I know in Java it's specified by "-Xmx" option. How do I set SBT up to use particular "-Xmx" value to run an application with "run" action?
Scala – How to specify JVM maximum heap size “-Xmx” for running an application with “run” action in SBT
sbtscala
Best Answer
For forked processes you should look at Build.scala
To modify the java options for forked processes you need to specify them in the Build.scala (or whatever you've named your build) like this:
This will give you the proper options without modifying JAVA_OPTS globally, and it will put custom JAVA_OPTS in an sbt generated start-script
For non forked processes it's most convenient to set the config via
sbtopts
orsbtconfig
depending on your sbt version.Since sbt 0.13.6
.sbtconfig
is deprecated. Modify/usr/local/etc/sbtopts
along these lines:You can also create an
.sbtopts
file in the root of your SBT project using the same syntax as in the/usr/local/etc/sbtopts
file. This makes the project self-contained.Before sbt 0.13.6 you could set the options in .sbtconfig for non forked processes:
Check where sbt is:
Look at the contents:
Set the correct jvm options to prevent OOM (both regular and PermGen):
If you want to set SBT_OPTS only for the current run of sbt you can use
env SBT_OPTS=".." sbt
as suggested by Googol Shan. Or you can use the option added in Sbt 12:sbt -mem 2048
. This gets unwieldy for longer lists of options, but it might help if you have different projects with different needs.Note that CMSClassUnloadingEnabled in concert with UseConcMarkSweepGC helps keep the PermGen space clean, but depending on what frameworks you use you might have an actual leak on PermGen, which eventually forces a restart.