skip to Main Content

As the title described, in Ubuntu 20.04 how to set Tomcat 9 to use Java 17 ?

Recently I repacked the war file of my web project with Spring Boot 3.0.1 which requires Java 17 to run, trying to deploy it to Tomcat 9 container at an Ubuntu 20.04 server.

It seems that the best way is to utilize the setenv.sh.

I’ve followed some documents,
created a folder bin in /usr/share/tomcat9, touched file of setenv.sh,
edited its content with JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64.

Then run sudo systemctl start tomcat9, but failed.
sudo systemctl status tomcat9 said "No JDK or JRE found – Please set the JAVA_HOME variable or install the default-jdk package",

Installed openjdk-17-jre-headless, and removed openjdk-11-jre-headless at first. Both Tomcat9 and JRE 17 is installed by apt package manager.

2

Answers


  1. Even if you managed to run tomcat 9 with java 17, a web app using spring boot 3.x or spring framework 6.x would still not be able to run there.

    Reason is that starting with spring boot 3.0 or spring framework 6.0 the web application needs to conform to jakarta servlet api. According to doc for tomcat the jakarta servlet api (servlet v5.0) is supported from tomcat 10 and later.

    As described in doc

    Apache Tomcat 10.0.x

    Apache Tomcat 10.0.x builds on Tomcat 9.0.x and
    implements the Servlet 5.0, JSP 3.0, EL 4.0, WebSocket 2.0 and
    Authentication 2.0 specifications (the versions required by Jakarta EE
    9 platform
    ).

    So you have to use tomcat 10 instead of tomcat 9.

    Login or Signup to reply.
  2. Well I have found this thread after finding the answer so I will write my solution If it can help anyone :

    Operating system : Ubuntu 22.04

    Installing Java : apt-get install openjdk-17-jdk

    Adding JAVA_HOME : nano /etc/environment

    -> JAVA_HOME="/usr/lib/jvm/java-17-openjdk-amd64"

    Then

    Installing Tomcat9 with : apt-get install tomcat9

    Starting tomcat9 with : service tomcat9 start

    An error is following stating JAVA_HOME is not found which is incorrect.

    You need to find the script /usr/libexec/tomcat9/tomcat-locate-java.sh

    Which actually seach for the versions 11 to 8 of Java.

    Updating the script this way adding the version 17 is solving the issue :

        find_jdks()
    {
        for java_version in 17 11 10 9 8
        do
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search