java jvm arg,如何解决“超出GC开销限制”使用maven jvmArg?

博客讲述运行Java类时出现OutOfMemoryError异常,尝试在Maven pom.xml中增加jvmArg堆大小无果。给出Java 7和Java 8的解决方案,Java 7通过设置MAVEN_OPTS环境变量分配内存,Java 8因用元空间替代永久代,设置有所不同。

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"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值