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?
views:
1364answers:
4No. 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.
Instead of double-clicking the .jar file directly, you can use a batch file that runs java -jar -Xms -Xmx your_file.jar
. From the user's point of view it's the same, but it gives you more control over the command that's actually run.
You can use JSmooth or a similar wrapper, which creates an EXE file that launches the JVM with the necessary parameters. That way you can avoid having a .bat file and its console dialog. Still one more way is to start the actual program in new process by using Runtime.exec or ProcessBuilder.
You can have the jar start itself again with Runtime.getRuntime().exec() with the options you want. The jar can contain more than one main() method (in different classes) and you can have one call the other via an exec().