Search code examples
scalamemory-managementout-of-memoryheap-memory

Increasing scala/java heap size in scala shell script


I have a scala shell script with the following header:

#! /bin/sh
env JAVA_OPTS="-Xmx20g"
exec scala -classpath ./target/scala-2.9.1/classes:lib/* "$0" "$@"
!#

Unfortunately, no matter how I set the JAVA_OPTS variable, the program terminates with an out of memory error.

How do I properly configure heap size in such a shell script without messing with global JAVA_OPTS environment variables?


Solution

  • From Scala help:

    Options to scala which reach the java runtime:

    ...

    -J<arg>         -J is stripped and passed to java as-is

    So, you can add -J-Xmx20g argument to scala.