I am trying to set the JVM of the server I am working on, so it dumps a heap to file when an OOME occurs.
I know I have to add this option -XX:-HeapDumpOnOutOf
As mentioned by @CoolBeans, the JVM options to use are:
-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=
For setting this in tomcat, create a file named setenv.sh (setenv.bat for windows) under TOMCAT_HOME/bin directory & add the following line
export CATALINA_OPTS="$CATALINA_OPTS -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath="
CATALINA_OPTS is preferred for these kind of options as they need not be applied to the shutdown process.