`
lxs647
  • 浏览: 517322 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

用mvn test运行test case时,报“java.lang.OutOfMemoryError: PermGen space”

 
阅读更多

在maven project中,test case的运行是少不了的。随着项目复杂度的增加,相应的test cases的数量也会随之增加。

 

突然有一天,用eclipse 内置的m2e插件Run as -> Maven test运行test cases,跑着跑着就报错如下:

“java.lang.OutOfMemoryError: PermGen space” error

 

Google了各种办法之后没有解决:

1.add 环境变量:

  Windows: set MAVEN_OPTS=-Xmx512m -XX:MaxPermSize=1024m

  Linux: export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=1024m"

2. adding -XX:MaxPermSize=1024M and -XX:PermSize=512M after -vmargs in the eclipse.ini

3. adding -XX:MaxPermSize=1024m and -XX:PermSize=512m to my Tomcat launch configuration

4. add VM arguments on my default JRE as following:Window -> Preferences -> Java -> Installed        JREs. Select the checked JRE/JDK and click edit, and set Default VM Arguments = -Xms128m -    Xmx1024m -XX:MaxPermSize=1024m

 

以上四种办法试了个遍,不知道是我打开的方式不对还是怎么回事儿,没有一个起作用,最后按照一篇博文(https://eureka.ykyuen.info/2010/03/02/maven-set-java-heap-memory-for-junit-in-maven-surefire-plugin/)中的设置,在pom.xml中添加参数如下:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.18.1</version>
    <configuration>
        <argLine>-XX:MaxPermSize=1024m</argLine>
    </configuration>
</plugin>

设置完了之后,再次运行mvn test or Run as ->Maven test,顺利跑完整个test。

博文中写到:

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.

在Stackoverflow(http://stackoverflow.com/questions/2819853/setting-java-heap-space-under-maven-2-on-windows) 有个post写到:

Basically the JUnits fork off into their own environment and ignore the settings in MAVEN_OPTS. You need to configure surefire in your pom to add more memory for the JUnits.

 

参考链接:

http://stackoverflow.com/questions/3101128/java-lang-outofmemoryerror-permgen-space-in-maven-build

http://stackoverflow.com/questions/24708077/java-lang-outofmemoryerror-permgen-space-after-convering-project-to-maven

http://stackoverflow.com/questions/2819853/setting-java-heap-space-under-maven-2-on-windows

https://eureka.ykyuen.info/2010/03/02/maven-set-java-heap-memory-for-junit-in-maven-surefire-plugin/

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics