Maven构建失败,超出了GC开销限制

时间:2018-10-22 20:01:32

标签: java maven

我正在尝试使用以下命令构建项目

mvn clean install 

但是每次都以内存问题结束,然后我使用-X选项运行相同的命令,并以详细错误结束

  

[错误]超出了GC开销限制-> [帮助1]   java.lang.OutOfMemoryError:超出了GC开销限制           在java.util.Arrays.copyOf(Arrays.java:3332)           在java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:124)           在java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:649)           在java.lang.StringBuilder.append(StringBuilder.java:202)           在aQute.bnd.osgi.Clazz.parseReference(Clazz.java:1807)           在aQute.bnd.osgi.Clazz.parseReferences(Clazz.java:1774)           在aQute.bnd.osgi.Clazz.parseDescriptor(Clazz.java:1756)           在aQute.bnd.osgi.Clazz.referTo(Clazz.java:1727)           在aQute.bnd.osgi.Clazz.parseClassFileData(Clazz.java:759)           在aQute.bnd.osgi.Clazz.parseClassFileData(Clazz.java:509)           在aQute.bnd.osgi.Clazz.parseClassFileWithCollector(Clazz.java:494)           在aQute.bnd.component.AnnotationReader.getDef(AnnotationReader.java:134)           在aQute.bnd.component.AnnotationReader.getDefinition(AnnotationReader.java:130)上           在aQute.bnd.component.DSAnnotations.analyzeJar(DSAnnotations.java:126)           在aQute.bnd.osgi.Analyzer.doPlugins(Analyzer.java:664)           在aQute.bnd.osgi.Analyzer.analyze(Analyzer.java:216)           在aQute.bnd.osgi.Builder.analyze(Builder.java:387)           在aQute.bnd.osgi.Analyzer.calcManifest(Analyzer.java:694)           在aQute.bnd.osgi.Builder.build(Builder.java:108)           在org.apache.felix.bundleplugin.BundlePlugin.buildOSGiBundle(BundlePlugin.java:972)           在org.apache.felix.bundleplugin.BundlePlugin.execute(BundlePlugin.java:467)           在org.apache.felix.bundleplugin.BundlePlugin.execute(BundlePlugin.java:384)           在org.apache.felix.bundleplugin.BundlePlugin.execute(BundlePlugin.java:375)           在org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)           在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)           在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)           在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)           在org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)           在org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)           在org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)           在org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)           在org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)[错误]   [ERROR] [ERROR]有关错误以及可能的更多信息   解决方案,请阅读以下文章:[错误] [帮助1]   http://cwiki.apache.org/confluence/display/MAVEN/OutOfMemoryError

因此,我尝试了上述异常的原因和解决方案,并在项目的父pom.xml文件中添加了以下几行,但仍然存在相同的问题

<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <fork>true</fork>
          <meminitial>512m</meminitial>
          <maxmem>1048m</maxmem>
        </configuration>
      </plugin>
    </plugins>
    [...]
  </build>
  [...]
</project>

然后我添加了

MAVEN_OPTS="-Xmx1024M -Xss128M -XX:MetaspaceSize=512M -XX:MaxMetaspaceSize=1024M -XX:+CMSClassUnloadingEnabled"

在环境变量的系统变量部分中,但这也无济于事。我正在使用Windows 10和Java版本8。

有人可以告诉我们解决方案吗?

2 个答案:

答案 0 :(得分:1)

添加这些系统变量将解决此问题

.exclude(id=request.user.id)

这可以添加到环境变量中。

https://reacttraining.com/react-router/web/guides/quick-start

答案 1 :(得分:0)

对于Windows,我通过使用以下命令修改环境GC overhead limit exceeded变量值来解决MAVEN_OPTS问题:

-Xmx1024M -Xss128M -XX:MetaspaceSize=512M -XX:MaxMetaspaceSize=1024M -XX:+CMSClassUnloadingEnabled