I am working on a rather complex java project with many dependencies and many unit tests.
I am using java 1.6.0_65 on mac (mavericks) with maven 3.0.5 with maven-sur
JVM options that can help:
-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=c:/dumps/
Note: You can use forward slashes.
Note 2: Make sure the folder exists and that the process has write permission. On recent windows systems, C:\ is write protected.
Note 3: Make sure you have enough free space to write the dump. The Java 9 documentation mentions that the system's temp folder will be used when the disk is full.
If there is no dump file, then you JVM didn't run out of memory.
The next option is -XX:ErrorFile= which allows to the JVM to log fatal errors.
-XX:+ShowMessageBoxOnError shows an error dialog if the JVM crashes.
Note: You can change the flags of a running JVM using the jinfo command.
Pass these options to Maven Surefire via the argLine option:
maven-surefire-plugin
@{argLine} -XX:+HeapDumpOnOutOfMemoryError -Xmx1g -XX:HeapDumpPath=H:/dumps/ -XX:ErrorFile=H:/dumps/ -XX:+ShowMessageBoxOnError
The strange @{argLine} at the beginning allows other plugins like Jacoco to inject their options. For this to work, you need to add an empty property:
You can verify that it works when the error happens: Maven will then dump the whole command line used to start the forked JVM.