在 m2e Eclipse 插件中增加堆大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7899221/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 20:37:40  来源:igfitidea点击:

Increase heap size in m2e Eclipse plugin

eclipsememorymavenheapm2e

提问by krams

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

如何增加 m2e Eclipse 插件的堆大小?基本上,我试图在 STS(SpringSource 的 Eclipse 版本)下使用 Cargo 和 Selenium 运行自动化集成测试,并预装了 m2e(Eclipse 的流行 Maven 插件)。

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.

我得到了臭名昭著的java.lang.OutOfMemoryError: Java heap space... 63M/63M。所以我先做了一些研究。通过 MAVEN_OPTS、Eclipse.ini / STS.ini、运行配置甚至通过 pom.xml 的 Maven 插件增加内存。没有改变。相同的错误和相同的内存量 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):

我知道我的项目有效。POM 是正确的。为什么?因为当我使用独立的 Maven 运行相同的命令时。Selenium 和 Cargo 的集成测试有效。事实上,这是最新的输出(3 分钟前):

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

我不是在问如何在独立的 Maven 命令中增加内存。我特别询问如何增加 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).

注意:默认情况下,m2e Eclipse 插件没有“验证”目标的快捷方式。您必须通过运行配置(没有 Args 选项卡,仅供参考)创建一个新的。

回答by crasp

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.

使用 Maven 2 插件时,在 eclipse.ini 或 MAVEN_OPTS 环境变量中设置 java 选项对您的构建没有影响。您需要通过 Eclipse 中的“编辑配置和启动”对话框添加一些命令行参数。

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

“Run As”>“Maven Build”,点击“JRE”选项卡,输入VM args eg

-Xms128M -Xmx512M

-Xms128M -Xmx512M

回答by vacao

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.

作为已经接受的答案的后续,当您在命令行上调用“mvn”时,您实际上是在调用 mvn.bat(或 mvn.sh)包装脚本。正是这个包装脚本在启动实际的 maven jvm 时使用了 MAVEN_OPTS 环境变量。

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.

另一方面,m2e 想要更多地控制 maven jvm 的启动方式,因此它直接在没有包装器的情况下执行此操作。这就是为什么您将内存设置直接添加到 m2e 运行/调试配置 VM 参数,而不是使用 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:

如果您希望 m2e 将您在 MAVEN_OPTS 中已有的内容传递给 maven jvm,请在 Eclipse 的“编辑配置和启动”对话框中:

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

“Run As”>“Maven Build”,点击“JRE”选项卡,输入VM args eg

${env_var:MAVEN_OPTS}

回答by davidpolo

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

您可以在 pom.xml 中添加您的内存设置:

<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

所有 maven-compiler-plugin 参数的描述在这里:链接

回答by Pete

Have you tried setting the MAVEN_OPTSenvironment variable for your run configuration?

您是否尝试过MAVEN_OPTS为您的运行配置设置环境变量?

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 hereor here

如果在运行配置中设置它没有帮助,您可能需要编辑系统环境变量。请参阅此处此处

回答by GokcenG

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.

我遇到过类似的问题。在 Windows 上创建一个名为 mavenrc_pre.bat 或在 linux 上在您的主文件夹中创建一个名为 .mavenrc 的文件,并根据需要在其中设置您的 maven_opts。它与 Eclipse Indigo 捆绑的 m2e 一起工作。