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.
CodePudding user response:
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.