Tuesday, March 2, 2010

Setting -Xmx for Scala compiler in Netbeans.

After upgrading to a latest Scala nightly I was no longer able to compile one of my projects. Clean and build would result in either "java.lang.OutOfMemoryError: GC overhead limit exceeded" or "java.lang.OutOfMemoryError: Java heap space".
An extensive google search revealed no solutions. Finally, after looking at the some source code, I was able to track down an undocumented option for Scala compiler ant plugin that Netbeans is using. I am posting a quick solution below. Hopefully it will be useful for someone who has stumbled upon the same problem.


Setting -Xmx for Scala compiler in Netbeans v6.8 using Scala-kit v0.16.1:

1. In Netbeans, open the file view of your project (tab "Files").

2. Navigate to "{project_home}/nbproject" and open "build-impl.xml".

3. find the following line:
scalac addparams="-make:transitive -dependencyfile ${basedir}/${build.dir}/.scala_dependencies @{addparams}" deprecation="${scalac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" extdirs="@{extdirs}" force="yes" fork="true" includes="@{includes}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="jvm-${javac.target}" unchecked="${scalac.unchecked}"

4. Add jvmargs option with desired jvm options (in this case jvmargs="-Xmx1024m")
scalac addparams="-make:transitive -dependencyfile ${basedir}/${build.dir}/.scala_dependencies @{addparams}" deprecation="${scalac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" extdirs="@{extdirs}" force="yes" fork="true" jvmargs="-Xmx1024m" includes="@{includes}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="jvm-${javac.target}" unchecked="${scalac.unchecked}"

5. Done. Now you can clean and build your project without OutOfMemoryError.