在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/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/
相关推荐
com.springsource.tcl.lang.jacl-1.4.1生成报错替换包.zip
maven常用指令大全Maven常用命令: 1. 创建Maven的普通java项目: mvn archetype:create -DgroupId=packageName -DartifactId=projectName ...5. 运行测试:mvn test 6. 产生site:mvn site
NULL 博文链接:https://swanmarx.iteye.com/blog/1778928
spring-petclinic-master运行mvn install报错:Failed to execute goal io.spring.javaformat:spring-javaformat-maven-plugin:0.0.19:validate (default) on project spring-petclinic: Formatting violations ...
数据库连接包,下载解压,使用命令 mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.5.0 -Dpackaging=jar -Dfile=(你的路径)\ojdbc14.jar