Can I set Java max heap size for running from a jar file?

Posted by Kip on Stack Overflow See other posts from Stack Overflow or by Kip
Published on 2009-06-19T14:23:01Z Indexed on 2010/05/16 11:20 UTC
Read the original article Hit count: 216

Filed under:
|
|

I am launching a java jar file which often requires more than the default 64MB max heap size. A 256MB heap size is sufficient for this app though. Is there anyway to specify (in the manifest maybe?) to always use a 256MB max heap size when launching the jar? (More specific details below, if needed.)


This is a command-line app that I've written in Java, which does some image manipulation. On high-res images (about 12 megapixels and above, which is not uncommon) I get an OutOfMemoryError.

Currently I'm launching the app from a jar file, i.e.

java -jar MyApp.jar params...

I can avoid an OutOfMemoryError by specifying 256MB max heap size on the command line, i.e.:

java -Xmx256m -jar MyApp.jar params...

However, I don't want to have to specify this, since I know that 256MB is sufficient even for high-res images. I'd like to have that information saved in the jar file. Is that possible?

© Stack Overflow or respective owner

Related posts about java

Related posts about jar