SoFunction
Updated on 2025-04-14

The relationship between Tomcat version and Java version and description

The relationship between Tomcat version and Java version

Tomcat version history

/dist/tomcat/

Corresponding Java version

Tomcat   5.0No specific descriptions are found in
Tomcat 5.5 is designed to run on J2SE 5.0 and later
Tomcat 6.0 is designed to run on Java SE 5.0 and later.
Tomcat 7.0 is designed to run on Java 6 and later.
Tomcat 8.0 is designed to run on Java SE 7 and later.
Tomcat 8.5 is designed to run on Java 7 and later.
Tomcat 9.0 is designed to run on Java 8 and later.
Tomcat 10.0 is designed to run on Java 8 and later.
Tomcat 10.1 is designed to run on Java 11 and later.
Tomcat 11.0 is designed to run on Java 17 and later.

What versions of Java does Tomcat support?

Tomcat supports multiple versions of Java, and the specific supported version depends on the version of Tomcat. Generally, each major version of Tomcat supports multiple Java versions, but it is recommended to use a Java version that is compatible with the Tomcat version for best performance and stability.

Tomcat compatibility with Java versions

Here are some common Tomcat versions and their recommended Java versions:

  • Tomcat : Java 7 or Java 8 is recommended.
  • Tomcat : It is recommended to use Java 8 or Java 9 and above.
  • Tomcat : It is recommended to use Java 11 or Java 17 (LTS version).

Example: Configuring Tomcat with Java 8

Install Java 8: Make sure Java 8 is already installed in the system and can be accessed via the command linejavaandjavacOrder.

  • Set JAVA_HOME environment variable:WillJAVA_HOMEThe environment variable is set to the installation path of Java 8.
export JAVA_HOME=/path/to/java8
  • Configure Tomcat: Edit Tomcat's(orOn Windows) File, SettingsJAVA_HOME
# Add the following line inexport JAVA_HOME=/path/to/java8
  • Start Tomcat: Start Tomcat using the configured environment variables.
./bin/

Example: Running a simple servlet under Java 8

Create a simple servlet to make sure it is compatible with Java 8.

import .*;
import .*;
import .*;

public class HelloWorldServlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        ("text/html");
        PrintWriter out = ();
        ("<html><body>");
        ("<h1>Hello, World!</h1>");
        ("</body></html>");
    }
}

existConfigure Servlet mapping in:

<web-app>
    <servlet>
        <servlet-name>hello</servlet-name>
        <servlet-class>HelloWorldServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>hello</servlet-name>
        <url-pattern>/hello</url-pattern>
    </servlet-mapping>
</web-app>

Summarize

Tomcat supports multiple Java versions, but the best practice is to use Java versions that are compatible with the Tomcat version. By setting the correct environment variables and configuration files, you can ensure that Tomcat runs with the specified Java version.

When developing and deploying Java web applications, the compatibility of Tomcat and Java versions should always be checked to ensure application stability and performance.

The above is personal experience. I hope you can give you a reference and I hope you can support me more.