javadeploymentheap-memoryjava-web-start

What is a good way to deploy a Java program and give JVM arguments?


Currently I have been deploying my application as a .jar file, because users of every OS can just double click it. However I now need to increase the max heap size, and the only way to do that is to pass a command-line argument (-Xmx1g) to the JVM. I wish it was possible to include this in the jar manifest, but it's not.

So now I am forced to include a .bat or .csh with the .jar that has the arguments. It seems like there is a better way to do this right? I don't think that Webstart is a good option because the .jar is meant to run in a user's directory where it writes out files. The application is a desktop GUI app.


Solution

  • Unfortunately it is not possible to specify vmargs in the manifest file inside your jar, so you need a workaround like :

    The first solution can be easily implement using a batch or an shell script for example, while for the second solution there are several alternatives that can be useful as for example the aforementioned and native Java Web Start and launch4j that is a Cross-platform Java executable wrapper. The third solution can be implemented in some situations and if your code is compatible with the GNU classpath library, in this case you could compile into native binary using GCJ .