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…)

If you try to do a large metadata deployment using the Migration Tool (a.k.a’s Apache Ant extension), then you’ll probably encounter this error:

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 development and deployment tools (hopefully) in the near future, so please stay tuned!


2 comments so far

  1. Mat Schaffer on

    Or you could just use the hoopla_salesforce gem and even get your meta.xml’s for free. 🙂

    • apexsutherland on

      Haha, I had a feeling you were going to chime in about that 🙂

      My audience for this post is the majority of admins and devs who need/want to stay in the Salesforce-supported “happy path”. Once we get hoopla_salesforce matching and/or exceeding the functionality of ant, then I’ll evangelize it more…

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: