Increase heap size in m2e Eclipse plugin

元气小坏坏 提交于 2019-11-30 13:13:31

问题


How does one increase the heap size of the m2e Eclipse plugin? Basically, I'm trying to run an automated integration test using Cargo and Selenium under STS (SpringSource's version of Eclipse) with pre-installed m2e (the popular Maven plugin for Eclipse).

Whenever I run

mvn verify

I get the infamous java.lang.OutOfMemoryError: Java heap space... 63M/63M. So I made some research first. Increase the memory via MAVEN_OPTS, Eclipse.ini / STS.ini, Run Configurations, and even via the Maven plugins thru the pom.xml. Nothing changed. Same error and same amount of memory 63M/63M.

I know my project works. The POM is correct. Why? Because when I run the same command using a stand-alone Maven. The integration test with Selenium and Cargo works. In fact here's the latest output (3 minutes ago):

[INFO] [beddedLocalContainer] Jetty 8.x Embedded is stopped
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4 minutes 24 seconds
[INFO] Finished at: Wed Oct 26 14:08:16 CST 2011
[INFO] Final Memory: 70M/149M
[INFO] ------------------------------------------------------------------------

I'm not asking how to increase the memory in stand-alone Maven command. I'm specifically asking how to increase the heap size for m2e.

Note: By default the m2e Eclipse plugin does not have shortcut to the "verify" goal. You have to create a new one via Run Configuration (which does not have an Args tab, fyi).


回答1:


When working with the Maven 2 plugin, setting java options in eclipse.ini or MAVEN_OPTS environment variable will have no effect on your build. You need to add some command line args via the "Edit Configuration and launch" dialog in Eclipse.

"Run As" > "Maven Build", click on the "JRE" tab, enter VM args e.g.

-Xms128M -Xmx512M




回答2:


As a follow-on to the already accepted answer, when you invoke "mvn" on the command-line, you are really invoking the mvn.bat (or mvn.sh) wrapper script. It is this wrapper script that uses the MAVEN_OPTS env variable when kicking off the actual maven jvm.

m2e, on the other hand, wants more control over how the maven jvm is kicked off, so it does this directly without the wrapper. This is why you add your memory settings directly to your m2e run/debug configuration VM arguments, rather than using MAVEN_OPTS.

If you want m2e to pass what you already have in MAVEN_OPTS to the maven jvm, in the "Edit Configuration and launch" dialog in Eclipse:

"Run As" > "Maven Build", click on the "JRE" tab, enter VM args e.g.

${env_var:MAVEN_OPTS}



回答3:


You can add in your pom.xml your memory settings:

<plugin>
 <artifactId>maven-compiler-plugin</artifactId>
  <configuration>
    ...
    <fork>true</fork>
    <meminitial>128m</meminitial>
    <maxmem>512m</maxmem>
    ...
  </configuration>
</plugin>

The description of all maven-compiler-plugin parameters is here: link




回答4:


Have you tried setting the MAVEN_OPTS environment variable for your run configuration?

MAVEN_OPTS="-Xmx768M -XX:MaxPermSize=128m" 

Might be you'll have to edit your system environment variables if setting it in the run configuration doesn't help. See here or here




回答5:


I've faced a similar issue. Create a file named mavenrc_pre.bat on windows or .mavenrc on linux in your home folder and set your maven_opts as you wish in it. It is working with m2e bundled with Eclipse Indigo.



来源:https://stackoverflow.com/questions/7899221/increase-heap-size-in-m2e-eclipse-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!