Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increasing memory size with maven-exec-plugin

I want to use maven-exec-plugin to run my class.

class ThisTestLauncher {
    public static void main(String[] args) throws Exception {
    System.out.println(
        ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax()
    );
}

pom:

<artifactId>exec-maven-plugin</artifactId>
<configuration>
   <mainClass>com.my.ThisTestLauncher</mainClass>
   <arguments>
      <argument>-Xms512m</argument>
      <argument>-Xmx2g</argument>
   </arguments>
</configuration>

Still, I see output to be 259522560, that's like 256m size. The same result for

<commandlineArgs>-Xms512m -Xmx2g</commandlineArgs>

What's wrong with it?

like image 842
awfun Avatar asked Sep 12 '25 22:09

awfun


1 Answers

<commandlineArgs> and <arguments> are passed to the main method. They are no JVM arguments.

As an alternative, use goal exec:exec and specify java -Xmx512m -Xmx2g com.my.ThisTestLauncher as your command to execute. See http://www.mojohaus.org/exec-maven-plugin/exec-mojo.html

like image 56
Matthias J. Sax Avatar answered Sep 15 '25 12:09

Matthias J. Sax