How do I configure the temp dir when using Java?

I have been notified my jobs are filling up /tmp on compute nodes. I am using a Java program. How can I instruct the Java Virtual Machine (JVM) to use a different directory?

To have Java use a different directory for temporary data, please use the following flag when starting the JVM.

-Djava.io.tmpdir=$DIR

Replace $DIR with the directory of your choice.