Search code examples
javamemoryjarheap-memory

Allocate more heap space to a Java jar


When you run a program through the command line, you can use java -Xms -Xmx to specify the heap sizes. If the program is going to be run by double clicking a .jar file, is there a way to use more heap than the standard?


Solution

  • No. That's why I often make a .bat or .sh file with those parameters and direct users to run it instead of the .jar. Unfortunately, it's a little ugly to have to pop up a command-prompt window, but that can't be helped.

    As a side benefit, if your application freezes, you can direct users to put pause into the batch file (or do it yourself), and then you can see any stack trace that occurs.

    Edit: You could also use an executable wrapper such as JSmooth or Launch4J instead of a batch file. You would lose some cross-platform compatibility, though.