Home > IT, linux, windows > Maven2 Heap Overflow in JUnit test cases: Howto increase memory

Maven2 Heap Overflow in JUnit test cases: Howto increase memory


For the past few days I was wondering why Maven’s install gave me a Heap Overflow exception on JUnit tests on some of my machines. I tried increasing the memory by using the environment variable MAVEN_OPTS, by passing the option “-Xmx512m” to the JVM through Eclipse and from the command line. All to no avail.

Then I found this blog entry by Keith Chapman. And it worked! Here’s the solution in short:

The JUnit tests ignore the environment variable MAVEN_OPTS. You have to tell Maven’s surefire plugin to increase memory. Add this to your pom.xml file:

    <argLine>-Xms512m -Xmx512m</argLine>
  1. Katrin
    2009/12/29 at 15:30

    thank you very much! you saved my day 🙂

  2. Evgeniy
    2010/03/31 at 12:25

    Do you know how to avoid this problem with


    I tried
    -Xms1024m -Xmx1024m
    But it didn’t help.

    • draptik
      2010/04/27 at 20:07

      Sorry, I don’t have an answer to that.

  3. Randy Wilson
    2010/10/28 at 17:34

    Thanks. That did the trick for me, too. (We were using surefire plugin elsewhere, but not in the project where I was having trouble).

  1. 2010/03/01 at 18:04
  2. 2011/01/11 at 02:01
Comments are closed.
%d bloggers like this: