tags:

views:

1364

answers:

4

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?

+2  A: 

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.

Michael Myers
@mmyers: Curse your fast little fingers! Beating me to it by 54 seconds!
Welbog
Sorry, I see you were busy editing the question. (I think that's the first time anyone has ever cursed my fast little fingers...)
Michael Myers
You could also use something like JSmooth: http://jsmooth.sourceforge.net/
Sii
@Sii: Yes, that's a somewhat more complicated route but it might be worth it.
Michael Myers
+2  A: 

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.

Welbog
+1 for giving the same answer I did. :)
Michael Myers
+1  A: 

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.

Esko Luontola
+2  A: 

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().

Peter Lawrey
Another good option (although it's not that easy to find out how much memory is available to use). +1
Michael Myers