java 为 Maven 将分拆的 Child JVM 进程设置 permgen 大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13161387/
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-10-31 11:42:43  来源:igfitidea点击:

Set the permgen size for the Child JVM processes that Maven will spin off

javamavenjenkinsmaven-jetty-pluginpermgen

提问by ecbrodie

I am building a Maven Java app on a Jenkins build server. I am running into java.lang.OutOfMemoryError: PermGen spacemany times during the build on Jenkins (but never on my localhost) and hence it fails my build.

我正在 Jenkins 构建服务器上构建一个 Maven Java 应用程序。我java.lang.OutOfMemoryError: PermGen space在 Jenkins 上的构建过程中遇到了很多次(但从来没有在我的本地主机上),因此我的构建失败了。

I have already tried setting MAVEN_OPTSfor Jenkins: I went into Jenkins-->Manage Jenkins-->Configure system-->Global MAVEN_OPTSand it was set to -Xms512m -Xmx1024m -XX:MaxPermSize=512m -XX:PermSize=512m. Despite setting it to this high value, we keep running into the PermGen space issues. I don't want to set the MAVEN_OPTS to a higher value; I do not see how my app can require a gig of space, and I'd rather dig deep into the high-memory-usage problem.

我已经尝试过MAVEN_OPTS为 Jenkins设置:我进入Jenkins--> Manage Jenkins--> Configure system-->Global MAVEN_OPTS并将其设置为-Xms512m -Xmx1024m -XX:MaxPermSize=512m -XX:PermSize=512m. 尽管将其设置为如此高的值,我们仍会遇到 PermGen 空间问题。我不想将 MAVEN_OPTS 设置为更高的值;我不知道我的应用程序如何需要大量空间,我宁愿深入研究高内存使用率问题。

Lately, I've been thinking that perhaps the permgen space issue is NOT coming from Maven itself but rather one of the JVM processes that Maven spins off (ex: plugins). I propose this hypothesis because Maven is still able to execute TestNG tests alright, despite already spitting our the permgen space error lines. One such plugin that is causing the PermGen error is Jetty:

最近,我一直在想,permgen 空间问题可能不是来自 Maven 本身,而是来自 Maven 衍生的 JVM 进程之一(例如:插件)。我提出这个假设是因为 Maven 仍然能够正常执行 TestNG 测试,尽管我们已经吐槽了我们的 permgen 空间错误行。一种导致 PermGen 错误的插件是Jetty:

Oct 31, 2012 7:55:37 AM com.google.apphosting.utils.jetty.JettyLogger warn
WARNING: handle failed
java.lang.OutOfMemoryError: PermGen space

Hence, I would like to know:

因此,我想知道:

Does the MAVEN_OPTSvariable also apply to child JVM processes that a Maven build spins off? If not, then how do I set the JVM options for these child processes such as Jetty?

MAVEN_OPTS变量是否也适用于 Maven 构建衍生的子 JVM 进程?如果没有,那么如何为这些子进程(例如 Jetty)设置 JVM 选项?

NOTE: I am using Maven 3.0.4.

注意:我使用的是 Maven 3.0.4。

采纳答案by Kkkev

Most Maven plugins that spawn Java processes will have their own way of specifying JVM command line arguments. For example, you can configure heap and permgen sizes in processes spawned by the Surefire plugin using the argLineconfiguration parameter (see http://maven.apache.org/plugins/maven-surefire-plugin/test-mojo.html#argLine).

大多数生成 Java 进程的 Maven 插件都有自己的方式来指定 JVM 命令行参数。例如,您可以使用argLine配置参数(请参阅http://maven.apache.org/plugins/maven-surefire-plugin/test-mojo.html#argLine)在 Surefire 插件产生的进程中配置堆和永久代的大小。

The Jetty plugin doesn't spawn processes, so heap and permgen are governed by JVM arguments provided to the Maven process.

Jetty 插件不产生进程,因此堆和永久代由提供给 Maven 进程的 JVM 参数控制。

If you are running out of memory when running from Jenkins but not when running locally, check the MAVEN_OPTS that Jenkins passes to Maven.

如果从 Jenkins 运行时内存不足,但在本地运行时没有内存不足,请检查 Jenkins 传递给 Maven 的 MAVEN_OPTS。

回答by Mehul

As mentioned previously by another reply that every process has its own way of specifying arguments. In case of maven sub process spawned by Jenkins the setting will be in the job configuration under the maven build. You need to click "Advanced" button and set the option in MAVEN_OPTSfield. eg : -XX:MaxPermSize=256m -Xms512m -Xmx1024m

正如之前在另一个回复中提到的,每个进程都有自己的指定参数的方式。如果 Jenkins 产生了 Maven 子进程,则设置将在 Maven 构建下的作业配置中。您需要单击“高级”按钮并在MAVEN_OPTS字段中设置选项。例如:-XX:MaxPermSize=256m -Xms512m -Xmx1024m

回答by sorencito

You can configure vm options globally (settings) and override it for any build job. E.g. in Maven based jobs, the MAVEN_OPTS field is hidden in one of the "advanced" blocks.

您可以全局配置 vm 选项(设置)并为任何构建作业覆盖它。例如,在基于 Maven 的作业中, MAVEN_OPTS 字段隐藏在“高级”块之一中。