Apache Tomcat Documentation
repository·main·Indexed 27 days ago
https://github.com/apache/tomcatAn open-source web server implementation of Jakarta EE technologies, including Servlet, JSP, WebSocket, and Expression Language. This documentation covers installation, configuration of the 'stuffed' distribution, Maven and Docker build processes, GraalVM native image compilation, OpenSSL API support via jextract, and server management using catalina.sh and catalina.bat.
What's inside Apache Tomcat
- Apache Tomcat is an open source implementation of the Jakarta Servlet, Jakarta Pages, Jakarta Expression Language, and Jakarta WebSocket technologies. It is designed to power large-scale, mission-critical web applications and is released under the Apache License version 2.
Build Tomcat Stuffed Native Image
mainTo run Tomcat in a container as a native image, refer to the official Tomcat documentation for
native-imageusage (found indocs/graal.html).Static Linking Considerations: If the container runtime is different from the build platform, use the
--staticparameter in thenative-imagecall to link base libraries (requireszlibandglibcstatic libraries).Important Limitation: TLS support is not available with static linking because TLS uses dynamic libraries (SunEC for JSSE and
tomcat-nativefor OpenSSL). If TLS is required, the native image must be built on a platform identical to the target platform.Get Support and Community Information
mainApache Tomcat provides several community-driven support channels:
- Community Support: Join the
tomcat-usersemail list for general community assistance. - Release Announcements: Subscribe to the
tomcat-announceemail list to receive information regarding new code releases, bug fixes, security fixes, and general news. - Bug Reporting: If you encounter a concrete bug, follow the official instructions at https://tomcat.apache.org/bugreport.html.
- General Resources: For additional help with running Tomcat, visit the resources page.
- Community Support: Join the
Configure Kubernetes Cluster Membership
mainWhen using the Kubernetes cloud clustering membership provider, the pod requires permission to view other pods. In OpenShift, you can grant this permission using the following command:
oc policy add-role-to-user view system:serviceaccount:$(oc project -q):default -n $(oc project -q)Configure Apache Tomcat for NetBeans IDE
mainTo use Apache Tomcat as a 'Free-Form Project' in NetBeans (allowing you to edit, build, and debug Tomcat and its unit tests), follow these steps:
- Prerequisite: Ensure you can successfully build and run tests using Apache Ant from a command prompt (refer to
BUILDING.txtin the Tomcat source root). - Generate Project Files: Run the following Ant target from the Tomcat source root to create the
nbprojectdirectory required by NetBeans:ant ide-netbeans - Configure Dependencies: NetBeans needs to know the location of Tomcat dependency JARs.
- If you have a
base.pathproperty defined in yourbuild.propertiesfile, NetBeans will detect it. - Warning: If
base.pathis left at its default, you MUST manually define this path in thenb-tomcat-project.propertiesfile.
- If you have a
- Open in NetBeans: Open the Tomcat directory in NetBeans. It should be recognized as a Free-Form project and validate the
nbproject/project.xmlfile.
Important Warnings:
- Do not use the Project Properties menu in NetBeans. Doing so may cause NetBeans to modify the configuration files and break the integration.
- If the configuration files are modified/corrupted, you can restore the defaults by running:
ant ide-netbeans-replace - Current NetBeans support does not include components in the
modulesdirectory (e.g.,tomcat-lite).
ant ide-netbeans- Prerequisite: Ensure you can successfully build and run tests using Apache Ant from a command prompt (refer to
Build Apache Tomcat Stuffed with Maven
mainTo build the project using Maven:
- Update the Tomcat version number in
pom.xml. - Customize Tomcat components in the dependencies to retain only necessary ones (only
tomcat-catalinais mandatory). - Add custom Tomcat component sources to the standard Maven build path to include them in the package.
Run the following command:
mvn clean; mvn package- Update the Tomcat version number in
Install Tomcat artifacts into your local Maven repository
mainTo install the Maven artifacts into your local Maven repository, use the
antbuild tool with themvn-pub.xmlfile and thegeneric-installtarget.ant -f mvn-pub.xml generic-installDebug an external Tomcat instance in NetBeans
mainYou can debug an external Tomcat instance (running on the same or a different machine) using the NetBeans Free-Form project, provided the external instance is running the same version of the source code.
- Prepare External Tomcat: Start the external Tomcat instance with JVM debugging enabled by adding arguments to
JAVA_OPTS. For example:-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n - Attach NetBeans:
- In NetBeans, select "attach debugger" from the debug menu.
- Select the JPDA debugger with the SocketAttach connector and the dt_socket transport.
- Specify the hostname and port where the Tomcat JVM is listening.
- Debug: Once connected, NetBeans will display running threads, allowing you to set breakpoints and inspect the external process.
-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n- Prepare External Tomcat: Start the external Tomcat instance with JVM debugging enabled by adding arguments to
Configure GraalVM Native Image reflection and resources
mainWhen compiling Apache Tomcat with GraalVM's
native-imagecompiler for Ahead of Time (AOT) compilation, specific directives are required to ensure reflection and resource files are correctly included in the native executable.These directives must be placed in the following directory structure within your JAR:
META-INF/native-image/<groupId>/<artifactId>/Required configuration files:
reflect-config.json: Defines which classes use reflection.resource-config.json: Ensures resource files normally included in a JAR are compiled into the executable image.
Build and Verify Tomcat in NetBeans
mainAfter configuring the project, verify the integration with the following actions in NetBeans:
- Clean: Run the
Cleanproject action to ensure the environment is ready. - Build: Run the
Buildaction. This calls the Tomcatdeploybuild target and should compile source files and create JARs. - Compile Tests:
- To compile a specific test file, select it and choose the
compileaction. - To ensure all changed test files are handled, use the
compileAllTestsproject action.
- To compile a specific test file, select it and choose the
- Run Tests: Select a unit test class and choose the "run selected file" action.
- Debug Tests: Set a breakpoint in a test case and request NetBeans to debug that class. You can then use standard debugging tools (display variables, navigate call stack, step through code).
- Clean: Run the
Add license headers to generated OpenSSL Java files
mainBefore committing any updated generated files, you must add the required license headers. Use theaddlicense.shscript to process all Java source files located in thesrc/main/java/org/apache/tomcat/util/openssldirectory.Build OpenSSL API support classes using jextract
mainTo use additional native APIs from OpenSSL or the stdlib, you can build the OpenSSL API support classes using
jextract(available in Java 22+).- Download
jextractfromhttps://jdk.java.net/jextract/. - Set the
JEXTRACT_HOMEenvironment variable to the extracted path. - Determine your system's include paths using
gcc -xc -E -v -(e.g., on Fedora, it might be/usr/lib/gcc/x86_64-redhat-linux/14/include). - Update
openssl-tomcat.confwith the correct include path. - Run the
jextractcommand using the configuration file to generate a trimmed-down OpenSSL API.
$JEXTRACT_HOME/bin/jextract @openssl-tomcat.conf openssl.h- Download