我正在使用带有 OSX Yosemite 的MacBook Pro。当我在我的java项目下运行maven clean install
时,我经常会收到错误:
java.lang.OutOfMemoryError: Java heap space
我google了一下,并按照建议添加环境变量来为maven设置更大的堆大小。
我编辑了〜/ .bash_profile ,添加了以下内容:
setenv MAVEN_OPTS "-Xmx1024M -XX:MaxPermSize=512m"
然后再次运行maven clean install
,但我仍然得到OutOfMemoryError
。我如何设置我的maven使用最大1024M堆?
===更新====
完整日志:
java.lang.OutOfMemoryError: Java heap space
at com.sun.tools.javac.file.ZipFileIndex$ZipDirectory.findCENRecord(ZipFileIndex.java:552)
at com.sun.tools.javac.file.ZipFileIndex$ZipDirectory.<init>(ZipFileIndex.java:497)
at com.sun.tools.javac.file.ZipFileIndex.checkIndex(ZipFileIndex.java:191)
at com.sun.tools.javac.file.ZipFileIndex.<init>(ZipFileIndex.java:137)
at com.sun.tools.javac.file.ZipFileIndexCache.getZipFileIndex(ZipFileIndexCache.java:100)
at com.sun.tools.javac.file.JavacFileManager.openArchive(JavacFileManager.java:559)
at com.sun.tools.javac.file.JavacFileManager.openArchive(JavacFileManager.java:482)
at com.sun.tools.javac.file.JavacFileManager.listContainer(JavacFileManager.java:368)
at com.sun.tools.javac.file.JavacFileManager.list(JavacFileManager.java:644)
at com.sun.tools.javac.jvm.ClassReader.fillIn(ClassReader.java:2446)
at com.sun.tools.javac.jvm.ClassReader.complete(ClassReader.java:2143)
at com.sun.tools.javac.code.Symbol.complete(Symbol.java:421)
at com.sun.tools.javac.comp.Enter.visitTopLevel(Enter.java:298)
at com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:459)
at com.sun.tools.javac.comp.Enter.classEnter(Enter.java:258)
at com.sun.tools.javac.comp.Enter.classEnter(Enter.java:272)
at com.sun.tools.javac.comp.Enter.complete(Enter.java:484)
at com.sun.tools.javac.comp.Enter.main(Enter.java:469)
at com.sun.tools.javac.main.JavaCompiler.enterTrees(JavaCompiler.java:929)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:824)
at com.sun.tools.javac.main.Main.compile(Main.java:439)
at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:132)
at org.codehaus.plexus.compiler.javac.JavaxToolsCompiler.compileInProcess(JavaxToolsCompiler.java:125)
at org.codehaus.plexus.compiler.javac.JavacCompiler.performCompile(JavacCompiler.java:169)
at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:823)
at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:129)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:106)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
答案 0 :(得分:0)
可能问题出在surefire插件运行的测试中。您应该在<argLine>
中使用surefire <configuration>
标记而不是MAVEN_OPTS中包含选项:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Xmx1g -XX:MaxPermSize=256m</argLine>
</configuration>
</plugin>
答案 1 :(得分:0)
虽然这是一个非常老的线程,但我认为值得补充的是,在使用maven-compiler-plugin时可以使用以下配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<maxmem>512m</maxmem>
</configuration>
</plugin>