Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven throws "java.lang.OutOfMemoryError"

I'm compiling an open source project with "mvn install" but ended up with java.lang.OutOfMemoryError: Java heap space. I tried to execute java -Xmx256m but the output was java synopsis which indicated it's an invalid command.

I'm using jdk1.5.0_08, any ideas why this is happening?

Thanks,

like image 220
user124858 Avatar asked Dec 17 '09 07:12

user124858


People also ask

How do I fix Java Lang OutOfMemoryError?

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.

How do I allocate more memory to Maven?

It is possible to start Maven and sbt with increased memory. We recommend you increase the Maximum Metaspace size and the Thread Stack size. These values can be set using -Xss2M -XX:MaxMetaspaceSize=1024M . The exact values may depend on your hardware and your code base.

What causes Java Lang OutOfMemoryError?

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.


2 Answers

Set the environment variable:

MAVEN_OPTS="-Xmx512m" 
like image 160
cletus Avatar answered Sep 18 '22 19:09

cletus


It depends on which JVM instance require more memory. As example, if tests are forked (by default), and fails due OutOfMemoryError then try configure plugin which launching them:

        <plugin>             <artifactId>maven-surefire-plugin</artifactId>             <configuration>                 <argLine>-Xmx1024m</argLine>             </configuration>         </plugin> 
like image 37
Andriy Plokhotnyuk Avatar answered Sep 21 '22 19:09

Andriy Plokhotnyuk