When running a class I have the following exception:
Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded
I've tried to increase the jvmArg heap size from inside maven pom.xml of the class package:
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
(...)
(...)
(...)
4g
${project.basedir}/..(...).basedir>
net.alchim31.maven
scala-maven-plugin
MyClassName
(...)
-Xmx${javaOpts.Xmx}
(...)
I've tried the last cited line with many values:
-Xmx512m{javaOpts.Xmx}
-Xmx4096M{javaOpts.Xmx}
...
-Xmx10000000000M{javaOpts.Xmx}
But for all of them I have the same error.
Anyone can help me?
Observation: I'm running from IntelliJ IDEA.
解决方案
Java 7
It's not a Maven issue, you need to give more memory to the VM. You do this via environment variables, and the Maven Launcher will automatically pick up these settings on load, and use them to configure the underlying Java VM.
The simple way to do it is to:
export MAVEN_OPTS="-Xmx1024M -Xss128M -XX:MaxPermSize=1024M -XX:+CMSClassUnloadingEnabled"
Windows:
set MAVEN_OPTS=-Xmx1024M -Xss128M -XX:MaxPermSize=1024M -XX:+CMSClassUnloadingEnabled
(No double quotes)
Java 8
Java 8 has replaced permanent generation with metaspace, and the new settings look like this:
export MAVEN_OPTS="-Xmx1024M -Xss128M -XX:MetaspaceSize=512M -XX:MaxMetaspaceSize=1024M -XX:+CMSClassUnloadingEnabled"
博客讲述运行Java类时出现OutOfMemoryError异常,尝试在Maven pom.xml中增加jvmArg堆大小无果。给出Java 7和Java 8的解决方案,Java 7通过设置MAVEN_OPTS环境变量分配内存,Java 8因用元空间替代永久代,设置有所不同。
966

被折叠的 条评论
为什么被折叠?



