• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Running java jar with ram of 2GB

 
Jacob Sonia
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, i want to run a jar from the command line and i want to specify that it needs 2 GB of memory
i think -Dkey=value would help me, but i don't know what should be the key in this case
i believe value would be -Xmx2048m

Please help
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To specify the memory settings you can use -Xmx and -Xms. -Xms specifies the minimum heapsize and -Xmx specifies the maximum size.
 
Jacob Sonia
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But how do i set it
i mean is it just java jar foo.jar -Xmx2048m

for me it didn't work this way
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That way you're giving the parameters as application parameters and not as jvm parameters. The correct syntax is:
java -jar -Xmx2048m foo.jar
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A 32-bit JVM cannot use more than 1.5GB of memory, at least on Windows. If you need more you will need to switch to a 64-bit JVM on a 64-bit Windows machine. This is not a limitation of the JVM but of Windows. I'm not sure if Linux has the same limitation.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:. . . I'm not sure if Linux has the same limitation.
It hasn't on my laptop; Fedora will happily use -Xmx2048M, but not -Xmx3072M. Maybe if I had paid a bit more and got more than 2GB RAM it would accept 3072!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic