I am launching a java jar file which often requires more than the default 64MB max heap size. A 256MB heap size is sufficient for this app though. Is there anyway to speci
There are many ways of doing it:
You can by having another Jar file which triggers your main Jar.
Or, have a batch file which will start your jar. But be careful, if downloaded from say net, the user will have to set permissions for the script to be runnable
Build an installer. On Mac, using the Oracle Java App bundler for Java 7, Apple App bundler for Java 6 build the .app file. You still cant redistribute it as the necessary permissions wont be set. Build a dmg for the app file. This can be used for distribution. A similar installer for Windows
The third technique would be the best, as you can then package the dependencies well, set all JVM arguments etc
YES! You need to write a small starter program - I wrote a small mostly cross platform compatible (paths should be fine) program to do it - see below. This has been tested on Windows/Ubuntu/Mac OS X.
Silent Development Blog article on increasing executable Java jar heap
Write a batch or shell script containing the following line. Put into the folder, where MyApp.jar is stored.
java -Xmx256M -jar MyApp.jar
After that always open this batch/script file in order to launch the JAR file. Although, This will not embed specification of virtual memory size into jar file itself. But, It can override the problem to write the same command often on command line.
Found an answer on google.
He says no for the JAR file, yes in JavaWeb Start, and that you should do it in your (possibly system-specific) launcher/wrapper script/app.
This isn't great, but you could have it as an executable JAR, and then in it's main, have it execute itself via the command-line as a non-daemon thread with the proper params stored in a properties file or calculated or whatever, then exit the original. You could even have it execute the jar with another "real" entry-point that expects those parameters.
Apparently this works on Ubuntu
> export _JAVA_OPTIONS="-Xmx1g"
java -jar jconsole.jar & Picked up _JAVA_OPTIONS: -Xmx1g