Monday, December 29, 2008

Java Heap Error in Maven JUnit Eclipse Environment

I encountered Java Heap Error (java.lang.outOfMemoryError) while running JUnit test cases using Maven plugin in Eclipse IDE. When maven build is run thru IDE, it forks another java process which kept running out of heap space after reaching only about 100M. After changing a number of different settings in IDE, Maven, OS environment variables and spending close to 8 hrs. Finally arrived at the solution.

First changed environment variable JAVA_OPTS to -Xms40m -Xmx1024m -XX:MaxPermSize=256m but no luck.

Second changed MAVEN_OPTS to -Xms40m -Xmx1024m -XX:MaxPermSize=256m but no luck.

Third changed eclipse.ini to have vm parameter -Xms40m -Xmx1024m -XX:MaxPermSize=256m but no luck. This file is so fragile, making changes here breaks eclipse pretty bad.

Fourth through IDE , Run Configuration -> Maven Build provided VM parameters -Xms40m -Xmx1024m -XX:MaxPermSize=256m -verbose but no luck.

Fifth changed IDE setting for JDK to use vm parameters -Xms40m -Xmx1024m -XX:MaxPermSize=256m but no luck

Sixth option worked like charmed, in maven pom.xml added following setting for the plugin that helps you run JUnit test cases. Added following to .pom file.

<plugin>
<groupid>org.apache.maven.plugins</groupid>
<artifactid>maven-surefire-plugin</artifactid>
<version>2.2</version>
<configuration>
<argline>-Xmx1024m</argline>
</configuration>
</plugin>

No comments: