3

Java 项目打包时 HeapSpace OOM

 2 years ago
source link: https://blog.victorchu.info/posts/54be8f14/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Java 项目打包时 HeapSpace OOM

发表于

2021-11-30 更新于 2022-03-04 分类于 FAQBuild Tool

Waline: 0 阅读次数: 本文字数: 1.1k 阅读时长 ≈ 2 分钟

Java 项目打包时 HeapSpace OOM

maven 打包时 HeapSpace OOM

maven 打包时出现 HeapSpace OOM 问题。由于 Maven 是 Java 启动的,显然我们只要修改 maven 进程的 JVM 配置就可以了。

在系统的环境变量中,设置 MAVEN_OPTS,用以存放 JVM 的参数:

export MAVEN_OPTS=-Xms256m -Xmx768m -XX:PermSize=128m -XX:MaxPermSize=256M

除了 Maven 主进程之外,单测插件 surefire 起的进程也可能出现 OOM 异常。surefire 插件可以拉出几个 JVM 进程,以及每个进程的 JVM 配置是如何的,都是可以配置的 (见官方文档)。

<!--注意argLine配置可以用于传递JVM参数-->
<plugins>
[...]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<forkCount>3</forkCount>
<reuseForks>true</reuseForks>
<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
<systemPropertyVariables>
<databaseSchema>MY_TEST_SCHEMA_${surefire.forkNumber}</databaseSchema>
</systemPropertyVariables>
<workingDirectory>FORK_DIRECTORY_${surefire.forkNumber}</workingDirectory>
</configuration>
</plugin>
[...]
</plugins>

gradle 打包时 HeapSpace OOM

在 gradle 工程的 gradle.properties 里配置 org.gradle.jvmargs=-Xmx2000m -Xms500M -XX:+HeapDumpOnOutOfMemoryError

坚持分享,您的支持将鼓励我继续创作!

欢迎关注我的其它发布渠道


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK