Change Eclipse Ant settings when you run out of memory

I use Ant a lot to compile AIR or Flex projects. When it comes to larger projects (especially when you compile multiple modules and libraries) you have to increase the amount of memory Ant is allowed to use. Otherwise you can get an exception like this:

[mxmlc] Loading configuration file PATH_TO_YOUR_SDK/flex_sdk_3.0.2.2095/frameworks/air-config.xml
[mxmlc] Error: PermGen space
[mxmlc] java.lang.OutOfMemoryError: PermGen space
[mxmlc] at java.lang.String.intern(Native Method)
[mxmlc] …

  • In Eclipse open menu: Run->External Tools->Open External Tools Dialog…
  • Select the build script you want to change on the left
  • Select the JRE tab on the right
  • Set the following as VM arguments: -Xms768m -Xmx1024m -XX:MaxPermSize=512m

These values work for me but you might want to change it to match your environment and project size.

Update: List of JVM options (via Cornel Creanga)

29 comments to Change Eclipse Ant settings when you run out of memory

  • Sometimes you have to configure also the PermGen memory size – especially if you have a huge number of classes (or JSP files) or you are pushing a lot of string into the constant pool. The parameter is:-XX:MaxPermSize, by default the value is 32mb for HotSpot client and 64 for HotSpot server.

  • Thanks Cornel! I updated my post with MaxPermSize which also solved one of my issues where I got this PermGen space error.

  • [...] If you start Ant scripts from Eclipse which is the way I use it all the time you can also run out of memory and I posted a couple of weeks ago how you can change the settings. [...]

  • [...] If you search for this error you’ll find many blogposts written by utterly frustrated Java developers. It appears to be a dreaded error that is raised when deploying war files to web or application servers. Fortunately, this article pointed me to the right solution for this problem: http://soenkerohde.com/2008/06/change-eclipse-ant-settings-when-you-run-out-of-memory/ [...]

  • Jithendra

    thanks for the solution i was actually looking for this from past a week. :-)

  • Still fails even after increasing the heap size .

    [mxmlc]
    [mxmlc] Error: Java heap space
    [mxmlc]
    [mxmlc] java.lang.OutOfMemoryError: Java heap space
    [mxmlc] at java.util.HashMap.(HashMap.java:203)
    [mxmlc] at java.util.HashSet.(HashSet.java:86)
    [mxmlc] at macromedia.asc.parser.ProgramNode.(ProgramNode.java:64)
    [mxmlc] at macromedia.asc.parser.NodeFactory.program(NodeFactory.java:1737)
    [mxmlc] at macromedia.asc.parser.Parser.parseProgram(Parser.java:7861)
    [mxmlc] at flex2.compiler.as3.Compiler.parse1(Compiler.java:250)
    [mxmlc] at flex2.compiler.API.parse1(API.java:2315)
    [mxmlc] at flex2.compiler.API.parse1(API.java:2268)
    [mxmlc] at flex2.compiler.API.batch2(API.java:369)
    [mxmlc] at flex2.compiler.API.batch(API.java:1117)
    [mxmlc] at flex2.compiler.API.compile(API.java:1290)
    [mxmlc] at flex2.compiler.API.compile(API.java:1210)
    [mxmlc] at flex2.tools.Compiler.mxmlc(Compiler.java:275)
    [mxmlc] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [mxmlc] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    [mxmlc] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    [mxmlc] at java.lang.reflect.Method.invoke(Method.java:585)
    [mxmlc] at flex.ant.FlexTask.executeInProcess(FlexTask.java:283)
    [mxmlc] at flex.ant.FlexTask.execute(FlexTask.java:225)
    [mxmlc] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
    [mxmlc] at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    [mxmlc] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    [mxmlc] at java.lang.reflect.Method.invoke(Method.java:585)
    [mxmlc] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    [mxmlc] at org.apache.tools.ant.Task.perform(Task.java:348)
    [mxmlc] at org.apache.tools.ant.Target.execute(Target.java:357)
    [mxmlc] at org.apache.tools.ant.Target.performTasks(Target.java:385)
    [mxmlc] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
    [mxmlc] at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
    [mxmlc] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    [mxmlc] at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
    [mxmlc] at org.apache.tools.ant.Main.runBuild(Main.java:758)

    D FAILED

  • Ferzerkerx

    thanks this solved my problem!!!

  • Nuwan

    Thanks!,
    This was helped me :)

  • Ramer

    Can this method work on Mac?
    The VM arguments edit box is un-editable on my Mac(both 10.5 and 10.6).

  • Yes, I am on a Mac too. So I assume you are missing something else.

  • Sai

    On the mac, go to /Application/eclipse/eclipse, Ctrl-Click on eclipse, select “Show Package Contents”, go into directory “Contents/MacOS” and edit eclipse.ini and throw in the parameters. For instance my eclipse.ini is –
    -showsplash
    org.eclipse.platform
    -startup
    ../../../plugins/org.eclipse.equinox.launcher_1.0.101.R34x_v20081125.jar
    –launcher.library
    ../../../plugins/org.eclipse.equinox.launcher.carbon.macosx_1.0.101.R34x_v20080731
    -vmargs
    -Xdock:icon=../Resources/Eclipse.icns
    -XstartOnFirstThread
    -Xms1024m
    -Xmx1024m
    -XX:MaxPermSize=1024m
    -Dosgi.requiredJavaVersion=1.5
    -Dorg.eclipse.swt.internal.carbon.smallFonts

    Hope this helps! thanks

  • Teodor GUTAN

    Excellent solution!!! BEst solution on the internet so far!

    Thanks a lot, man!!!!

  • Manish Thakur

    Thanks a lot for the solution.

  • Ravi

    Thanks for the solution.U saved my time

  • Sher

    Thanks friend. It worked for me !

  • tyvm mate, it solved my problem with eclipse compiling :)

  • Aschwin Wester

    Thanks,

    The term ‘PermGen space’ referred indeed to -XX:MaxPermSize=512m
    I could not find the eclipse location to change the setting.
    This was the solution, so thanks

  • [...] muss man etwas ausprobieren; mein Wert weicht von der Quelle ab, und die nutzt andere Einstellungen als ihre [...]

  • Tushar

    Hi Guys,

    I added following params in eclipse.ini file and also added to class Arguments, however still getting error-
    “java.lang.OutOfMemoryError: PermGen space”

    Can some one tell me the permanent solution to this issue?

    -vmargs
    -XX:PermSize=1024m
    -XX:MaxPermSize=1024m
    -Xms512m
    -Xmx512m

  • dll

    Thanks worked perfectly, we’re running Zelix Klass Master to obfuscate our web app, and I’ve been running into java heap errors when it comes to obfuscating the classes. Your steps worked perfectly, it’s really not trivial to find in Eclipse! Thanks again!

  • Utkarsh Chachad

    What must i do if i am running the ant task from command line & not from Eclipse??

  • Under OSX add this to your ~/.profile: export ANT_OPTS=”-Xms512m -Xmx512m”

  • Utkarsh Chachad

    Sorry I did not get u … I don’t have any knowledge or prior exp of flex command line builds. Can you please elaborate? Where do I find OSX & where exactly do i type “export ANT_OPTS=”-Xms512m -Xmx512m”

  • Utkarsh Chachad

    Also i am running this for windows so if your are talking in terms of linux then its no use. Thnx

  • Thanks mate!

    It solved my headache.

    Cheers!

    Tamas

  • chathuraka

    thanks for sharing.. had this issue for a while

  • Karthik

    Sorry to resurrect a dead post. But this solution saved me a lotta time.

    Thanks,
    Karthik J

  • NagRock

    Thanks!

  • Billy Ding

    Thanks. It works like a charm.