Force.com Migration Tool (Ant) out of memory solution
(This is a pretty un-glamorous resuscitation of my blog, but it was fresh on my mind and needed to be shared, so here goes…)
java.lang.OutOfMemoryError: Java heap space
Thankfully I was able to find the solution to this issue on the DeveloperForce discussion boards with some targeted Googling, but I’m hoping that this post will save others from having to encounter the error in the first place and then hack around for a while figuring out how to implement the fix.
The solution to this problem is pretty basic – all you need to do is to add the parameter “-Xmx1024m” to the “$ANT_OPTS” environment variable in your Ant shell script or batch file. (This parameter raises the maximum memory limit for your Java virtual machine to 1GB, instead of 128MB or whatever paltry amount the default is.) If you’re using the default installation of Ant on Mac OS X, you can find the Ant shell script in the “/usr/share/ant/bin” folder. Open “ant” with any text editor (my favorite is the free app TextWrangler) and go to line 322 of the file. Insert “-Xmx1024m” in between “$ANT_OPTS” and “-classpath”, save the file (you’ll probably need to provide your Mac OS X user account password since it is technically a system file), and you should be all set.
My condolences to the Windows users, as I don’t really use Windows any more, so you’ll have to figure out where that parameter goes. (If someone can post comprehensive instructions for Windows users as a comment, that would be greatly appreciated! I’ll be happy to update this post with the instructions.)
I’m planning to post some more extensive tips and guides on Force.com development and deployment tools (hopefully) in the near future, so please stay tuned!