Maven error from memory

To date, my maven compiler is not working.

[INFO] [ERROR] Unexpected [INFO] java.lang.OutOfMemoryError: Java heap space [INFO] at java.util.Arrays.copyOfRange(Arrays.java:2694) [INFO] at java.lang.String.<init>(String.java:203) [INFO] at java.lang.String.substring(String.java:1877) 

[ERROR] Out of memory; to increase the amount of memory use the -Xmx flag at startup (java -Xmx128M ...)

As of yesterday, I have successfully compiled maven.

To date, I just typed my bunch up to 3 GB . In addition, I only changed 2-3 minor lines of code, so I do not understand this error “out of memory”.

 vagrant@dev:/vagrant/workspace$ echo $MAVEN_OPTS -Xms1024m -Xmx3000m -Dmaven.surefire.debug=-Xmx3000m 

EDIT: I tried the comment on the poster by modifying my failed pom.xml module. But I got the same maven build error.

  <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.5</source> <target>1.5</target> <fork>true</fork> <meminitial>1024m</meminitial> <maxmem>2024m</maxmem> </configuration> </plugin> 
+83
maven out-of-memory maven-3 maven-compiler-plugin
Sep 19 '12 at 16:13
source share
12 answers

What kind of "network" module are you talking about? Is it a simple war and has a packing type war?

If you are not using the Google Web Toolkit (GWT), you do not need gwt.extraJvmArgs

Building a compilation process might not be a good idea, because it starts a second process that completely ignores MAVEN_OPTS , which makes analysis more difficult.

So I would try increasing Xmx by setting MAVEN_OPTS

 export MAVEN_OPTS="-Xmx3000m" 

And do not decompose the compiler into another process

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.5</source> <target>1.5</target> </configuration> </plugin> 

Increasing -XX:MaxPermSize=512m not required, because if the cause of the problem is the size -XX:MaxPermSize=512m , then I expect the error java.lang.OutOfMemoryError: PermGen space

If this does not solve your problem, you can create heap dumps for further analysis by adding -XX:+HeapDumpOnOutOfMemoryError . Alternatively, you can use jconsole.exe in your java bin directory to connect to jvm at compile time and see what happens inside the jvm heap.

Another idea (maybe stupid) that came to me, do you have enough RAM inside your machine? Determining the amount of memory is good, but if your host has only 4 GB, and then you may have a problem that Java cannot use certain memory, because it is already used by the OS, Java, MS-Office ...

+126
Sep 22
source share

Responding later to mention another option, not the general environment variable MAVEN_OPTS , to pass Maven to create the necessary JVM parameters.

Since Maven 3.3.1 , you can have the .mvn folder as part of the corresponding project and a jvm.config as the ideal place for such an option.

two new additional configuration .mvn/jvm.config and .mvn/maven.config located in the base directory of the project source tree. If present, these files will provide the default jvm and maven options. Since these files are part of the project source tree, they will be present in all project checks and will be automatically used every time the project is created.

As part of the official release notes

In Maven, it is easy to define the JVM configuration for each project base. The existing mechanism, based on the MAVEN_OPTS environment MAVEN_OPTS and the use of ${user.home}/.mavenrc , is another option with a drawback not included in the project.

Starting with this version, you can define the JVM configuration using the file ${maven.projectBasedir}/.mvn/jvm.config , which means that you can determine the parameters for your assembly based on each project. This file will become part of your project and will be checked along with your project. So the MAVEN_OPTS , .mavenrc files are no longer needed. For example, if you entered the following JVM parameters in the file ${maven.projectBasedir}/.mvn/jvm.config :

 -Xmx2048m -Xms1024m -XX:MaxPermSize=512m -Djava.awt.headless=true 

The main advantage of this approach is that the configuration is isolated for the corresponding project and applies to the entire assembly, as well as less fragile than MAVEN_OPTS for other developers working in the same project (forgetting to install it).
In addition, the parameters will be applied to all modules in the case of a multi-module project.

+30
Mar 14 '16 at 21:50
source share

I had the same problem trying to compile a “clean install” using VPS Lowend 512Mb and a good processor. Run OutOfMemory and run the script again.

I used export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=350m" and worked.

Some compilation still occurs, because the first time I need Maven, but the OutOfMemory problem went away.

+13
Jan 19 '15 at 6:06
source share

Add option

 -XX:MaxPermSize=512m 

at MAVEN_OPTS

maven-compiler-plugin options

  <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.5.1</version> <configuration> <fork>true</fork> <meminitial>1024m</meminitial> <maxmem>2024m</maxmem> </configuration> </plugin> 
+11
Sep 19 '12 at 16:50
source share

What type of OS are you using?

To assign more than 2 GB of memory, it must be at least 64-bit OS.

Then another problem arises. Even if your OS has unlimited RAM, but it is fragmented in such a way that there is not a single free block of 2 GB, you will also get exceptions from memory. And keep in mind that regular heap memory is only part of the memory that the VM process uses. Thus, on a 32-bit machine, you probably can never install Xmx on 2048 MB.

I would also suggest setting the minimum memory to the same value, because in this case, as soon as the VM runs out of memory, the 1GB start time is allocated from the beginning, then the VM allocates a new block (provided that it increases from 500 MB blocks) 1.5 GB after it is allocated, it will copy all materials from one block to a new one and free up memory after that. If the memory allotted 2 GB again and then 1.5 GB are copied, temporarily allocating 3.5 GB of memory.

+3
Sep 28 '12 at 14:46
source share

I had the same problem while compiling Druid.io, finally MaxDirectMemorySize worked.

 export MAVEN_OPTS="-Xms8g -Xmx8g -XX:MaxDirectMemorySize=4096m" 
+3
Mar 02 '17 at 12:32
source share
 _JAVA_OPTIONS="-Xmx3G" mvn clean install 
+3
Nov 17 '18 at 13:53
source share

This below configuration works in my case

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>${maven-surefire-plugin.version}</version> <configuration> <verbose>true</verbose> <fork>true</fork> <argLine>-XX:MaxPermSize=500M</argLine> </configuration> </plugin> 

Try using -XX: MaxPermSize instead of -XX: MaxPermGen

+2
Feb 11 '18 at 20:40
source share

When building a project on a Unix / Linux platform, set the syntax for the Maven parameters as shown below. Note that single cavitation characters, not double quotes.

 export MAVEN_OPTS='-Xmx512m -XX:MaxPermSize=128m' 
+1
Jul 19 '18 at 6:18
source share

Using .mvn / jvm.config worked for me, plus it has an added advantage associated with the project.

0
Mar 23 '16 at 18:39
source share

This happens on large Windows projects when using cygwin or another linux emulator (git bash). By some coincidence, both are not working on my project, which is a big open source project. In the sh script, a couple of mvn commands are called. The size of the memory increases to a heap size larger than specified in Xmx, and most of the time if the second Windows process starts. This makes memory consumption even higher.

The solution in this case is to use a batch file and a reduced Xmx size, and then the maven operations will succeed. If there is interest, I can disclose more detailed information.

0
Jan 07 '19 at 20:48
source share

Someone already mentioned a problem with a 32-bit OS. In my case, the problem was that I compiled with a 32-bit JDK.

0
Aug 22 '19 at 9:22
source share



All Articles