How to set maximum jvm memory (XMX) for jar file

How to set maximum jvm memory without adding extra batch script program to my Program. The answer is given below.

+5
source share
1 answer

This is a good question, but your aspiration involves a lot. I assume that you should document the name of your jar for your users to call "java -jar xyz.jar", so that you can also include in the documentation that "-Xmx256M" is required?

You may have more luck with a java launcher, for example this one for Windows, where you set the launch configuration (path, max memory, etc.) in a separate file. For the cross platform, there are LaunchAnywhere and others that work similarly. See How to convert my Java program to a .exe file?

To improve the existing scheme:

  • use system property java.hometo resolve JDK / JRE location
  • use java.class.pathto set the class path and similarly java.library.pathif your application requires native code.
  • pass command arguments passed to your main method to the spanwed process

, , , , , .

+3

All Articles