Maven – Set Java Heap Memory for JUnit in maven-surefire-plugin

Previously i have talked about setting Java Heap Memory in Maven.

But i find that the OutOfMemoryError still exists when running the JUnit test during build. =.=

After searching in Google, i realize that in Maven
JUnit tests ignore the environment variable MAVEN_OPTS and the JVM settings in Run Configurations.

So if u have OutOfMemoryError when running unit test in Maven, you have to set the Java Heap Memory in the maven-surefire-plugin inside the pom.xml.

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-surefire-plugin</artifactId>
	<version>2.5</version>
	<configuration>
		<argLine>-Xms512m -Xmx512m</argLine>
	</configuration>
</plugin>

Done =)

Reference:

5 thoughts on “Maven – Set Java Heap Memory for JUnit in maven-surefire-plugin”

  1. Thanks for pointing out this option!
    I’ve had to profile the memory consumption with jconsole of my mvn test build to realize that JUnit isn’t picking up its memory settings from MAVEN_OPTS.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s