Ahead of Time compilation support

Table of Contents


Tomcat supports using the GraalVM/Mandrel Native Image tool to produce a native binary including the container. This documentation page describes the build process of such an image.


The native image tool is much easier to use with single JARs, as a result the process will use the Maven shade plugin JAR packaging (fat JAR). The idea is to produce a single JAR that contains all necessary classes from Tomcat, the webapps and all additional dependencies. Although Tomcat has received compatibility fixes to support native images, any library may not be compatible and may require replacement code (the GraalVM documentation has more details about this).

Download and install GraalVM or Mandrel.

If using GraalVM, the first step is then to add the Native Image tool.

export JAVA_HOME=/absolute...path...to/graalvm-ce-javaX-x.y.z
cd $JAVA_HOME/bin
./gu install native-image
Mandrel already includes the Native Image tool ready to use, so this step can be skipped. Only JAVA_HOME must be set to the folder which contains the bin folder with the JVM binaries, such as:
export JAVA_HOME=/absolute...path...to/mandrel-javaXX-platform-x.x.x.x/mandrelJDK

Download the Tomcat Stuffed module from https://github.com/apache/tomcat/tree/main/modules/stuffed and place all the files in a folder stuffed in this documentation.

export TOMCAT_STUFFED=/absolute...path...to/stuffed
The build process now requires both Ant and Maven.

Packaging and Building

Inside the tomcat-stuffed folder, the directory structure is