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
, , , , , .