Out of memory error in ant

33,170

Solution 1

I solved it.

It had nothing to do with little memory. It was an endeless loop in my javadoc generation.

The correct way of setting more memory for ant is by using export ANT_OPTS=-Xmx256m on *nix.

On Windows follow the usual steps for setting environment variables.

Solution 2

The javac ant task has the attribute memoryMaximumSize which you should set to the same value as you would for -Xmx.

<javac memoryMaximumSize="256m" ...>
  ...
</javac>

I should add that this assumes that it is indeed a javac task that's causing the memory overrun.

Share:
33,170
Shervin Asgari
Author by

Shervin Asgari

Senior Java Developer and Architect Trekkie Linux Ubuntu User My private homepage is here My Civilization Boardgame from Fantasy Flight games implementation is here and if you want to follow me on twitter, I am @ShervinAsgari

Updated on July 09, 2022

Comments

  • Shervin Asgari
    Shervin Asgari almost 2 years

    I am trying to run ant task, however I get the following error:

    [javadoc] javadoc: error - java.lang.OutOfMemoryError: Please increase memory.
    [javadoc] For example, on the Sun Classic or HotSpot VMs, add the option -J-Xmx
    [javadoc] such as -J-Xmx32m.
    [javadoc] 1 error
    [javadoc] 103 warnings
    

    I have tried googling to find out how I can set this value, but I cannot find it. I have tried

    <javadoc maxmemory="256m">
    

    I have tried

    export ANT_OPTS=-Xmx256m
    

    but I still get the same exception. I have tried to increase the value to 1024m witouth any success

    Update

    I solved it. It had nothing to do with little memory. It was an endeless loop in my javadoc generation.

  • Mike Yockey
    Mike Yockey over 13 years
    Was it the same behavior because the amount of memory didn't change where you needed it or did you not allocate enough memory? Bear in mind too that changing the max memory size can affect the sizes of the heap and the stack differently. Increasing the amount of memory may actually result in a smaller stack or heap in some instances. Some experimentation will be necessary.
  • Shakti Malik
    Shakti Malik over 11 years
    Hi How did you find out that there is endless loop ?. I am facing similar issue while dexing the classes.
  • Shervin Asgari
    Shervin Asgari over 11 years
    There was an endlees loop in the code we had where we where generating javadoc.
  • user5403501
    user5403501 almost 11 years
    The above option must be combined with fork="true" to work. This will run javac in a separate process with its own heap size settings. This will also limit any memory leaks in javac implementation to its own child process, without affecting the parent Ant process.
  • Patrice M.
    Patrice M. almost 10 years
    Can you please elaborate ? The loop was between javadoc references ? If so, how can you get more info about the loop itself, how can one trace that loop ?
  • Shervin Asgari
    Shervin Asgari almost 10 years
    The loop was in our code that generated the javadoc