Tuesday, November 17, 2009

Javac OutOfMemory error while compiling with Ant

Did you get this OutOfMemory error message from javac  while compiling with ant:

“The system is out of resources.
Consult the following stack trace for details.
java.lang.OutOfMemoryError: Java heap space”

Well there is an easy way to fix it! first set property “fork” to true, this will allow javac to execute in a separate thread with its own resources, then you can set the values for “memoryinitialsize” and “memorymaximumsize” according to your needs. Here is a sample of how the javac task would look.

 <javac  
     fork="true"
     srcdir="${basedir}/src"  
     destdir="${basedir}/build/classes"  
     classpath="${project.classpath}"  
     memoryinitialsize="256m"  
     memorymaximumsize="256m"
 />  

That’s it! I hope it helps ;)
blog comments powered by Disqus