Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build Failed java.lang.OutOfMemoryError: Java heap space

Tags:

java

build

ant

I am facing this issue while building my build.xml.

BUILD FAILED java.lang.OutOfMemoryError: Java heap space     at java.util.Arrays.copyOf(Arrays.java:2786)     at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:94)     at org.codehaus.cargo.module.DefaultJarArchive.<init>(DefaultJarArchive. java:75)     at org.codehaus.cargo.module.DefaultJarArchive.<init>(DefaultJarArchive. java:56)     at org.codehaus.cargo.module.webapp.DefaultWarArchive.<init>(DefaultWarA rchive.java:69)     at org.apache.cactus.integration.ant.CactifyWarTask.addJarWithClass(Cact ifyWarTask.java:652)     at org.apache.cactus.integration.ant.CactifyWarTask.addCactusJars(Cactif yWarTask.java:627)     at org.apache.cactus.integration.ant.CactifyWarTask.execute(CactifyWarTa sk.java:519)     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)     at sun.reflect.GeneratedMethodAccessor31.invoke(Unknown Source)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces sorImpl.java:25)     at java.lang.reflect.Method.invoke(Method.java:597)     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav a:106)     at org.apache.tools.ant.Task.perform(Task.java:348)     at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:62)     at net.sf.antcontrib.logic.IfTask.execute(IfTask.java:197)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl. java:39)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces sorImpl.java:25)     at java.lang.reflect.Method.invoke(Method.java:597)     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav a:106)     at org.apache.tools.ant.TaskAdapter.execute(TaskAdapter.java:154)     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)     at sun.reflect.GeneratedMethodAccessor31.invoke(Unknown Source)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces sorImpl.java:25)     at java.lang.reflect.Method.invoke(Method.java:597)     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav a:106)     at org.apache.tools.ant.Task.perform(Task.java:348)     at org.apache.tools.ant.Target.execute(Target.java:357)     at org.apache.tools.ant.Target.performTasks(Target.java:385)     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)     at org.apache.tools.ant.Project.executeTarget(Project.java:1306) 
like image 874
vibhas Avatar asked Sep 21 '11 05:09

vibhas


People also ask

How do I fix Java Lang OutOfMemoryError Java heap space?

OutOfMemoryError: Java heap space. 1) An easy way to solve OutOfMemoryError in java is to increase the maximum heap size by using JVM options "-Xmx512M", this will immediately solve your OutOfMemoryError.

What causes Java Lang OutOfMemoryError Java heap space?

lang. OutOfMemoryError exception. Usually, this error is thrown when there is insufficient space to allocate an object in the Java heap. In this case, The garbage collector cannot make space available to accommodate a new object, and the heap cannot be expanded further.

What is OutOfMemoryError Java heap space?

OutOfMemoryError is a runtime error in Java which occurs when the Java Virtual Machine (JVM) is unable to allocate an object due to insufficient space in the Java heap. The Java Garbage Collector (GC) cannot free up the space required for a new object, which causes a java. lang.


1 Answers

It sounds like you need to launch your JVM with a larger memory limit. Try something like (if you're using Bourne shell):

export ANT_OPTS=-Xmx1g ant 

or, if you use cmd under Windows:

set ANT_OPTS=-Xmx1g ant 

Above, the 1g means 1 GB. You can tweak that to whatever you like; for example, if you want to use 1.5 GB, you can use -Xmx1536m.

like image 186
Chris Jester-Young Avatar answered Oct 05 '22 16:10

Chris Jester-Young