今天maven install时碰到的两个问题(堆溢出和编译错误)

时间:2021-10-27 15:51:47

问题1.maven install时出现,日志如下:

系统资源不足。
有关详细信息,请参阅以下堆栈追踪。

java.lang.OutOfMemoryError: Java heap space
at com.sun.tools.javac.util.List.prepend(List.java:145)
at com.sun.tools.javac.jvm.ClassReader.openArchive(ClassReader.java:1457)
at com.sun.tools.javac.jvm.ClassReader.list(ClassReader.java:1742)
at com.sun.tools.javac.jvm.ClassReader.listAll(ClassReader.java:1882)
at com.sun.tools.javac.jvm.ClassReader.fillIn(ClassReader.java:1903)
at com.sun.tools.javac.jvm.ClassReader.complete(ClassReader.java:1538)
at com.sun.tools.javac.code.Symbol.complete(Symbol.java:355)
at com.sun.tools.javac.comp.Enter.visitTopLevel(Enter.java:256)
at com.sun.tools.javac.tree.Tree$TopLevel.accept(Tree.java:382)
at com.sun.tools.javac.comp.Enter.classEnter(Enter.java:221)
at com.sun.tools.javac.comp.Enter.classEnter(Enter.java:235)
at com.sun.tools.javac.comp.Enter.complete(Enter.java:444)
at com.sun.tools.javac.comp.Enter.main(Enter.java:429)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:404)
at com.sun.tools.javac.main.Main.compile(Main.java:592)
at com.sun.tools.javac.main.Main.compile(Main.java:544)
at com.sun.tools.javac.Main.compile(Main.java:92)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.ja
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccesso
at java.lang.reflect.Method.invoke(Method.java:592)
at org.codehaus.plexus.compiler.javac.JavacCompiler.compileInProcess(Javac
at org.codehaus.plexus.compiler.javac.JavacCompiler.compile(JavacCompiler.
at org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMo
at org.apache.maven.plugin.CompilerMojo.execute(CompilerMojo.java:114)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginM
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(Defaul
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLife
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(Default
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandl
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLife at org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMo
at org.apache.maven.plugin.CompilerMojo.execute(CompilerMojo.java:114)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginM
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(Defaul
... 17 more
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 minutes 34 seconds
[INFO] Finished at: Wed Jul 20 17:22:53 CST 2011
[INFO] Final Memory: 60M/63M
[INFO] ------------------------------------------------------------------------

  

原因分析:虚拟机堆溢出,默认只有63M,工程比较多时容易出现此问题

解决方案:在maven启动脚本(mvn.bat)中,重新设置堆大小(set MAVEN_OPTS= -Xms128m -Xmx512m)

问题2:maven install时出现此问题,日志如下:

[INFO] Trace
org.apache.maven.BuildFailureException: Compilation failure
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(Defa
ultLifecycleExecutor.java:699)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLi
fecycle(DefaultLifecycleExecutor.java:540)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(Defau
ltLifecycleExecutor.java:519)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHan
dleFailures(DefaultLifecycleExecutor.java:371)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmen
ts(DefaultLifecycleExecutor.java:332)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLi
fecycleExecutor.java:181)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:356)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:137)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:356)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430) at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.CompilationFailureException: Compilation fail
ure
at org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompiler
Mojo.java:516)
at org.apache.maven.plugin.CompilerMojo.execute(CompilerMojo.java:114)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPlugi
nManager.java:483)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(Defa
ultLifecycleExecutor.java:678)

  

原因分析:编译不通过,检查JDK版本

解决方案:使用正确的JDK版本,和开发时的一致