10



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?

trincot
  • 317,000
  • 35
  • 244
  • 286
gennad
  • 5,335
  • 12
  • 44
  • 47
  • Is it giving a OutOfMemoryError? Did you try with -XX:MaxPermSize=1024m ? freeMemory() shows the space for future allocation. And permament objects goes to Perm space. Udo. – ssedano Jan 11 '11 at 09:37
  • If I try -XX:MaxPermSize=1024 nothing changes... I can't test it now on OutOfMemoryError... You mean that this space (for future allocation) will increase depending on application's needs? – gennad Jan 11 '11 at 09:44
  • maxMemory() shows the total amount of memory. Paste maxMemoryoutput please – ssedano Jan 11 '11 at 12:55
  • freeMemory(): 25288024 maxMemory(): 259522560 , seems max memory is in ten times more than free – gennad Jan 11 '11 at 18:31

2 Answers2

17

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
mhaller
  • 14,122
  • 1
  • 42
  • 61
  • I had to reread twice to ''get it'' get it, but then solved all my problems :-) Thanks. Saved quite some time I would have lost fiddling with stuff. – Peter Perháč Sep 25 '11 at 12:35
2

I think -DMAVEN_OPTS="-Xmx1024m -Xms512m" is not correct way to specify memory params here.

Set a env variable called MAVEN_OPTS with content "-Xmx1024m -Xms512m"

Zac Thompson
  • 12,401
  • 45
  • 57
lweller
  • 11,077
  • 3
  • 34
  • 38
  • You mean mvn jetty:run -Xmx1024m -Xms512m ? It doesn't run. mvn jetty:run -DXmx1024m -DXms512m runs, but the memory is the same like with MAVEN_OPTS – gennad Jan 11 '11 at 18:35
  • sorry my fault thew only way I think ist to set an env variable – lweller Jan 12 '11 at 07:42