Increase heap size in m2e Eclipse plugin

2020-02-25 08:22发布

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).

5条回答
我命由我不由天
2楼-- · 2020-02-25 08:25

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.

查看更多
Summer. ? 凉城
3楼-- · 2020-02-25 08:29

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}
查看更多
放荡不羁爱自由
4楼-- · 2020-02-25 08:37

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

查看更多
▲ chillily
5楼-- · 2020-02-25 08:41

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

查看更多
小情绪 Triste *
6楼-- · 2020-02-25 08:43

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

查看更多
登录 后发表回答