2

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.

trincot
  • 317,000
  • 35
  • 244
  • 286
pieter3d
  • 135
  • 6
  • Looks like duplicate http://stackoverflow.com/questions/2848346/how-do-i-set-maximal-jvm-memory-xmx-for-a-jar-file – Piotr Kochański Apr 17 '12 at 20:42
  • 2
    *"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."* Except for "run in a user's directory" (which is irrelevant nonsense, since a trusted JWS app. can read/write any file that is accessible by other Java apps.) JWS can do all that with one hand tied behind it's back. Use [Java Web Start](http://stackoverflow.com/tags/java-web-start/info). – Andrew Thompson Apr 18 '12 at 03:51

2 Answers2

2

Webstart seems like a good way to achieve that, and if you have the right permissions, nothing prevents you from reading from / writing to the user's file system.

It also provides several interesting "features", including:

  • the possibility to push upgrades to the user transparently
  • checking that the user is using the right version of the JRE

In your case, you would just need to use the following syntax:

<j2se version="1.7+" java-vm-args="-Xmx1g" href="http://java.sun.com/products/autodl/j2se"/>
assylias
  • 321,522
  • 82
  • 660
  • 783
2

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

  • Create a script that launch the jar file with specified vm args
  • Wrap your jar inside an executable that will work as a launcher
  • Compile your Java code into native binary

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 .

aleroot
  • 71,077
  • 30
  • 176
  • 213