Java Memory for Tomcat

Last modified by Eleni Cojocariu on 2026/11/25 14:50

Explanation

When running XWiki on Tomcat, you may encounter Out Of Memory errors similar to the following:

java.lang.OutOfMemoryError: Java heap space
java.lang.OutOfMemoryError: PermGen space

Cause

This is happening because the default Tomcat memory settings are not enough for XWiki Memory Requirements.

Solution

You could try to free some heap memory (e.g. delete cache, the recycle bin) or increase the memory allocated to the JVM used by Tomcat.

If Tomcat was installed and configured manually, one common approach is to create a setenv.sh file (Linux/macOS) or setenv.bat file (Windows) inside the TOMCAT_HOME/bin/ directory, (where TOMCAT_HOME is where you've installed Tomcat) and inside this file add or adjust the following. Example:

CATALINA_OPTS="-Xmx1024m"

setenv.sh/setenv.bat is read by bin/catalina.sh/catalina.bat and supports both CATALINA_OPTS and JAVA_OPTS; CATALINA_OPTS is conventionally used for options specific to Tomcat/Catalina, while JAVA_OPTS is used for generic JVM options, either works here.

This example allocates a maximum heap size of 1 GB to the JVM. Adjust the value according to your XWiki instance size and usage requirements.

Linux-specific alternatives

If Tomcat was installed through your Linux distribution's package manager instead (e.g. Installation using Debian/Ubuntu (.DEB) packages), it does not use bin/catalina.sh or setenv.sh; memory settings must instead be configured through distribution-specific configuration files such as:

/etc/default/tomcatX
/etc/tomcatX/tomcatX.conf
/etc/conf.d/tomcatX.conf

(where X is the installed Tomcat version).

In this case, only JAVA_OPTS is supported, CATALINA_OPTS is not read by the systemd service provided by the distribution package. Example:

JAVA_OPTS="-Djava.awt.headless=true -Xmx1024m"

Windows service installations

If Tomcat is installed as a Windows service, setting CATALINA_OPTS may not affect the running service. In that case, use the Tomcat service configuration utility located in the bin/ directory of the Tomcat installation. Examples:

tomcat9w.exe
tomcat10w.exe

The utility allows configuring JVM options, including the maximum heap size.

Restart Tomcat after modifying the JVM memory settings for the changes to take effect.

Get Connected