maven mvn运行出错

今天在buildGlassFish源码时出现错误,后来在mvn后加上 -X,打印出详细信息出如下:
[INFO] Scanning for projects...
[ERROR] Java heap space -> [Help 1]
java.lang.OutOfMemoryError: Java heap space
        at org.apache.maven.model.Dependency.clone(Dependency.java:204)
        at org.apache.maven.model.DependencyManagement.clone(DependencyManagemen
t.java:67)
        at org.apache.maven.model.ModelBase.clone(ModelBase.java:190)
        at org.apache.maven.model.Model.clone(Model.java:260)
        at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultMode
lBuilder.java:279)
        at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultMode
lBuilder.java:232)
        at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBu
ilder.java:410)
        at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBu
ilder.java:379)
        at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBu
ilder.java:495)
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions, please rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/OutOfMemoryErr
or

转到相应的wiki页查看,原因如下:

   1. You are building a very big multi-module project, each module requires a certain amount of memory so with increasing number of modules the amount of required memory increases as well until the JVM finally runs out of "Java heap space".
   2. You are using some plugins that perform memory-intensive operations like analyzing the class files of all project dependencies.
   3. You are using the Maven Compiler Plugin with the option fork=false (default) and your project has a lot of source files to compile. When using the Java compiler in embedded mode, each compiled class will consume heap memory and depending on the JDK being used this memory is not subject to gargabe collection, i.e. the memory allocated for the compiled classes will not be freed. The resultant error message typically says "PermGen space".

Fixing this error is usually just a matter of assigning more memory to the JVM. If you run from the command line, this can be done by means of the environment variable MAVEN_OPTS. This variable can be used to specify options for the JVM itself. In case of "Java heap space", the option of interest is -Xmx, in case of "PermGen space" it's usually -XX:MaxPermSize. For example, on Windows you would use

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

设置后再次运行mvn ,可能正常执行了。

猜你喜欢

转载自chainhou.iteye.com/blog/1766645