Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Free heap size does not increase in Maven



When I run maven-jetty-plugin, I run next command:

mvn -DMAVEN_OPTS="-Xmx1024m -Xms512m" -Djetty.port=8080 jetty:run

but when I try to output free heap size with

Long heapFreeSize = Runtime.getRuntime().freeMemory();

It always outputs something about about 30000000.
I suppose it's size in bytes, so about 30 megabytes.
Why then free heap memory did not increase?

like image 399
gennad Avatar asked Jan 11 '11 09:01

gennad


People also ask

How do I allocate more memory to Maven?

You can use the MAVEN_OPTS environment variable to set the maximum allowed heap size for Maven at a global level. The following command will set the heap size in Linux. Make sure that the value set as the maximum heap size does not exceed your system memory of the machine that runs Maven.

How do I increase Maven available memory by setting environment variable?

You can start Maven with extra memory using MAVEN_OPTS environment variable. In this example we're setting an initial JVM Heap of 512Mb, a maximum Heap of 1024M, a thread stack of 2M and maximum Metaspace size of 1024M.

Can we increase heap size?

To increase the Application Server JVM heap sizeNavigate to the JVM options. Edit the -Xmx256m option. This option sets the JVM heap size. Set the -Xmx256m option to a higher value, such as Xmx1024m.


1 Answers

MAVEN_OPTS is an environment variable, which is read by Maven and used as the command line arguments for forking java processes. Command line arguments control how the Java executable is started, e.g. stuff like memory settings.

-D is used for setting Java System Properties, which is something completely different than command line arguments. Java System Properties can be read programmatically, e.g. by using System.getProperties().

Windows:

SET MAVEN_OPTS="-Xmx1024m -Xms512m"
mvn -Djetty.port=8080 jetty:run

Linux:

export MAVEN_OPTS="-Xmx1024m -Xms512m"
mvn -Djetty.port=8080 jetty:run
like image 124
mhaller Avatar answered Sep 21 '22 05:09

mhaller