Java Maven:OutOfMemoryError - 堆空间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24412503/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 12:04:05  来源:igfitidea点击:

Maven: OutOfMemoryError - heap space

javamacosmavenintellij-idea

提问by VB_

Problem:I run mvn clean install -DskipTestand get

问题:我运行mvn clean install -DskipTest并得到

[ERROR] The system is out of resources.
[ERROR] Consult the following stack trace for details.
[ERROR] java.lang.OutOfMemoryError: Java heap space

More informaiton:

更多信息:

  • Operation system:OS X (16 GB RAM)

  • Java configurations:located at ~/Libraries/Preferences/IntelliJIdea13/idea.vmoptinsand Applications/IntelliJ\ Idea\ 13.app/bin/idea.vmoptions

    -Xms256m -Xmx2048m -XX:MaxPermSize=1024m -XX:ReservedCodeCacheSize=256m -XX:+UseCompressedOops

  • MAVEN_OPTS:export MAVEN_OPTS="-Xmx2048M -XX:PermSize=92M -XX:MaxPermSize=384M"located at ~/.bash_profile

  • Intellij Idea maven opts:-xms256m -xmx2048 -XX:MaxPermSize=1024M. I set them in Default Settings-> MAven-> Runner-> VM Options

  • 操作系统:OS X(16 GB RAM)

  • Java 配置:位于~/Libraries/Preferences/IntelliJIdea13/idea.vmoptinsApplications/IntelliJ\ Idea\ 13.app/bin/idea.vmoptions

    -Xms256m -Xmx2048m -XX:MaxPermSize=1024m -XX:ReservedCodeCacheSize=256m -XX:+UseCompressedOops

  • MAVEN_OPTS:export MAVEN_OPTS="-Xmx2048M -XX:PermSize=92M -XX:MaxPermSize=384M"位于~/.bash_profile

  • Intellij Idea maven 选择:-xms256m -xmx2048 -XX:MaxPermSize=1024M. 我将它们设置在Default Settings-> MAven-> Runner->VM Options

Question:How to solve?

问题:如何解决?

Stacktrace:

堆栈跟踪:

[ERROR] The system is out of resources.
[ERROR] Consult the following stack trace for details.
[ERROR] java.lang.OutOfMemoryError: Java heap space
[ERROR] at com.sun.tools.javac.util.Position$LineMapImpl.build(Position.java:139)
[ERROR] at com.sun.tools.javac.util.Position.makeLineMap(Position.java:63)
[ERROR] at com.sun.tools.javac.parser.Scanner.getLineMap(Scanner.java:1113)
[ERROR] at com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:512)
[ERROR] at com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:550)
[ERROR] at com.sun.tools.javac.main.JavaCompiler.parseFiles(JavaCompiler.java:804)
[ERROR] at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:727)
[ERROR] at com.sun.tools.javac.main.Main.compile(Main.java:353)
[ERROR] at com.sun.tools.javac.main.Main.compile(Main.java:279)
[ERROR] at com.sun.tools.javac.main.Main.compile(Main.java:270)
[ERROR] at com.sun.tools.javac.Main.compile(Main.java:87)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[ERROR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[ERROR] at java.lang.reflect.Method.invoke(Method.java:597)
[ERROR] at org.codehaus.plexus.compiler.javac.JavacCompiler.compileInProcess(JavacCompiler.java:554)
[ERROR] at org.codehaus.plexus.compiler.javac.JavacCompiler.compile(JavacCompiler.java:161)
[ERROR] at org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:605)
[ERROR] at org.apache.maven.plugin.CompilerMojo.execute(CompilerMojo.java:128)
[ERROR] at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
[ERROR] at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
[ERROR] at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
[ERROR] at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
[ERROR] at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
[ERROR] at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project com.conductor.thrift.client: Compilation failure
Failure executing javac, but could not parse the error:

采纳答案by Jigar Joshi

Java compiler plugin goes out of memory based on the comments above, to fix this you need to give Java compiler plugin more memory and to that inside your pom.xmladd this

Java编译器插件根据上面的评论内存不足,要解决这个问题,你需要给Java编译器插件更多的内存,并在你的内部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>