Tips for dealing with javac OutOfMemoryError
When javac is compiling a large number of java source files, it may fail with java.lang.OutOfMemoryError:
The system is out of resources.
Consult the following stack trace for details.
java.lang.OutOfMemoryError: Java heap space
It’s no different than OutOfMemoryError in other java applications. When you run javac in Sun JDK, it’s invoking com.sun.tools.javac.main.Main located in %JAVA_HOME%\lib\tools.jar.
If you are compiling with javac task in Apache Ant, set fork attribute to true, to run javac in a separate process with its own heap size settings. If fork is set to false, or not set (default is false), javac will run in the same process as Ant, which has a default maximum heap size of 64m.
<javac fork="true">
srcdir="${basedir}/src"
destdir="${basedir}/build/classes"
classpath="${project.classpath}"
memoryinitialsize="256m"
memorymaximumsize="256m">
</javac>
Setting fork to true will also limit any memory leaks in javac implementation to its own child process, without affecting the parent Ant process.