Sometimes is usefull to limit the maximum heap size for java. (Especially in a OpenVZ virtual machine(VPS) where java memory managment is terrible: http://www.r00t.gr/2011/03/openvz-vps-and-java-error-and-how-to-fix-it/)You can do this with the xmx parametr of command line java, but if you run many programs, with crons and through other programs, you will need a way to globaly set that (and any other java command line argument).

To set this globally, you must add something to the .bashrc file.

vi ~/.bashrc

and add:

export _JAVA_OPTIONS=-Xmx16m

You see that you can easily add any more parametrs you want (xms classpath etc)

That will take care whenever you manually start a java program. But if you run them with crons (like me) this won’t work. You have to add it to your cron file

crontab -e

and add the line:

_JAVA_OPTIONS="-Xmx16m"

That’s it. Thanks