Sure, here’s the translation: 增加Maven的JVM内存

huangapple go评论66阅读模式
英文:

Maven - increase memory for JVM

问题

我尝试了多种方法来增加JVM的内存分配。
操作系统是:Ubuntu 18.04.03 LTS。
我使用exec-maven-plugin来启动程序。
我使用以下命令启动它:mvn clean compile exec:java

然而,我需要更多的内存。
要检查JVM的内存分配情况,我使用:Runtime.getRuntime().maxMemory()(当前为32GB,系统上有120GB)。

为了增加内存分配,我尝试了多种方法。
1)使用surefire插件:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.5</version>
    <configuration>
        <argLine>-Xmx102400m</argLine>
    </configuration>
</plugin>

System.out.println(Runtime.getRuntime().maxMemory()) 仍然输出32GB。

2)set MAVEN_OPTS="-Xmx102400m"
3)mvn clean install -DargLine="-Xmx102400m"
(老实说,我甚至不知道为什么这样会起作用。)

由于程序在服务器上运行,我不能使用IntelliJ或Eclipse来增加JVM内存。
我已经没有任何思路了,在网上也找不到其他解决方案。

英文:

I have tried multiple ways to increase the given memory for the JVM.
The OS is: Ubuntu 18.04.03 LTS
To start the program I use the exec-maven-plugin.
I start it with following command: mvn clean compile exec:java.

However I need more memory.
To check the given memory for the jvm I use: Runtime.getRuntime().maxMemory(). (Currently it's 32gb, 120gb are on the system)

To increase it I have tried multiple things.

  1. Using the surefire plugin:
&lt;plugin&gt;
        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
        &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
        &lt;version&gt;2.5&lt;/version&gt;
        &lt;configuration&gt;
            &lt;argLine&gt;-Xmx102400m&lt;/argLine&gt;
        &lt;/configuration&gt;
&lt;/plugin&gt;

System.out.println(Runtime.getRuntime().maxMemory()) still prints 32gb.

  1. set MAVEN_OPTS=&quot;-Xmx102400m&quot;
  2. mvn clean install -DargLine=&quot;-Xmx102400m&quot;
    (To be honest I don't even have an idea why this should work.)

I can't use intellij or eclipse to increase the jvm memory, since the program runs on a server.
I don't have any idea left and I can't find an other solution on the web.

答案1

得分: 2

这个参数应该能起作用:-Drun.jvmArguments=" -Xmx512m -xms1024"

英文:

This argument should do the trick: -Drun.jvmArguments=&quot;-Xmx512m -xms1024&quot;

huangapple
  • 本文由 发表于 2020年8月28日 22:36:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/63635895.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定