185

我在构建 Maven 项目时遇到了这个错误,我增加了 MAVEN_OPTS 但都是一样的,我发现了一些类似的帖子,但它们指的是别的东西。我该如何解决?

The system is out of resources.
Consult the following stack trace for details.
java.lang.OutOfMemoryError: PermGen space
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
        at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at org.codehaus.plexus.compiler.javac.IsolatedClassLoader.loadClass(IsolatedClassLoader.java:56)
        at com.sun.tools.javac.comp.Annotate.<init>(Annotate.java:52)
        at com.sun.tools.javac.comp.Annotate.instance(Annotate.java:36)
        at com.sun.tools.javac.jvm.ClassReader.<init>(ClassReader.java:215)
        at com.sun.tools.javac.jvm.ClassReader.instance(ClassReader.java:168)
        at com.sun.tools.javac.main.JavaCompiler.<init>(JavaCompiler.java:293)
        at com.sun.tools.javac.main.JavaCompiler.instance(JavaCompiler.java:72)
        at com.sun.tools.javac.main.Main.compile(Main.java:340)
        at com.sun.tools.javac.main.Main.compile(Main.java:279)
        at com.sun.tools.javac.main.Main.compile(Main.java:270)
        at com.sun.tools.javac.Main.compile(Main.java:87)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.plexus.compiler.javac.JavacCompiler.compileInProcess(JavacCompiler.java:420)
        at org.codehaus.plexus.compiler.javac.JavacCompiler.compile(JavacCompiler.java:141)
        at org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:493)
        at org.apache.maven.plugin.CompilerMojo.execute(CompilerMojo.java:114)
        at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535)

我并不担心如何在 Maven 生态系统中修复它

4

7 回答 7

312

当你说你增加MAVEN_OPTS了,你增加了什么值?您是否增加了MaxPermSize,例如:

export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=128m"

(或在 Windows 上:)

set MAVEN_OPTS=-Xmx512m -XX:MaxPermSize=128m

您还可以在每个 maven 项目中分别指定这些 JVM 选项。

于 2010-06-23T11:32:30.923 回答
24

如果你想让你的 POM 的这一部分用于可重复的构建,你可以使用一些插件的 fork-variant(尤其是compiler:compilesurefire:test):

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.2</version>
    <configuration>
      <fork>true</fork>
      <meminitial>128m</meminitial>
      <maxmem>1024m</maxmem>
      <compilerArgs>
        <arg>-XX:MaxPermSize=256m</arg>
      </compilerArgs>
    </configuration>
  </plugin>

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.18</version>
    <configuration>
        <forkCount>1</forkCount>
        <argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
    </configuration>
</plugin>
于 2014-12-03T23:16:59.913 回答
16

当然,增加你的烫发空间的大小。使用该-XX:MaxPermSize=128m选项。将值设置为适当的值。

于 2010-06-23T11:31:50.977 回答
1

当我遇到这个异常时,我通过使用 Run Configurations... 面板解决了这个问题,如下图所示。特别是在 JRE 选项卡上,VM 参数是关键
“-Xmx1024m -Xms512m -XX:MaxPermSize=1024m -XX:PermSize =512 米”)。

在此处输入图像描述

于 2017-03-09T13:40:58.210 回答
1

这个非常烦人的错误,所以我做了什么:在 Windows 下:

Edit system environment variables - > Edit Variables -> New

然后填写

MAVEN_OPTS
-Xms512m -Xmx2048m -XX:MaxPermSize=512m

在此处输入图像描述

然后重新启动控制台并再次运行 maven 构建。不再有 Maven 空间/烫发大小问题。

于 2017-06-26T11:29:21.150 回答
0

当您尝试使用 git mvn clean install for “java.lang.OutOfMemoryError: PermGen space” in Maven build error come 构建战争时,我找到了 git bash 命令的解决方案

use below command first 

$ export MAVEN_OPTS="-Xmx512m -Xss32m"

then use your mvn command to clean install /build war file

$ mvn clean install

NOTE: you don't need -XX:MaxPermSize argument in MAVEN_OPTS when your are using jdk1.8
Java HotSpot(TM) Client VM warning: ignoring option MaxPermSize=XXXm; support was removed in 8.0
于 2017-01-12T10:45:33.457 回答
0

当永久代堆满时我们会遇到这个错误,我们中的一些人使用命令提示符在 Windows 中构建我们的 maven 项目。因为我们需要增加堆大小,我们可以设置我们的环境变量 @ControlPanel/System 和 Security/System 然后点击 更改设置并选择高级并设置环境变量如下

  • 变量名:MAVEN_OPTS
  • 变量值:-XX:MaxPermSize=128m
于 2017-04-12T12:05:35.593 回答