Tomcat10 Spring Boot 3 — Java 17 deployment on Ubuntu Server
Hello! Today we will deploy our spring boot application on a remote server. While trying to deploy my java17 spring boot app. I faced some…

Tomcat10 Spring Boot 3 & Java 17 deployment on Ubuntu Server
Hello! Today we will deploy our spring boot application on a remote server. While trying to deploy my java17 spring boot app I faced some issues and there was no resource. That’s the motivation for this article :) Thanks to Erkan Yenier for their support.
I am using Linode however you can use other alternatives.
First, we need to create a server. You can choose the lowest-priced server ($5 per month).


Now we are ready to go! Let’s connect to our server via SSH:
ssh root@<IP_ADDRESS>
Then allow SSH (If you don’t allow, it may cause errors sometime after connecting) and update
sudo ufw allow ssh
sudo apt update
We will install Java 17 on our machine and set JAVA_HOME path
sudo apt-get install openjdk-17-jdk
sudo update-java-alternatives --list
sudo update-java-alternatives --set java-1.17.0-openjdk-amd64
java -version
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
echo $JAVA_HOME
Now install Tomcat and give permissions
sudo groupadd tomcat
sudo useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat
cd /tmp
wget https://dlcdn.apache.org/tomcat/tomcat-10/v10.1.15/bin/apache-tomcat-10.1.15.tar.gz
sudo mkdir /opt/tomcat
cd /opt/tomcat
sudo tar xzvf /tmp/apache-tomcat-10.*tar.gz -C /opt/tomcat --strip-components=1
sudo chown -R tomcat:tomcat /opt/tomcat
sudo chmod -R u+x /opt/tomcat/bin
sudo chown -R tomcat webapps/ work/ temp/ logs/
We have to configure Tomcat. Don’t forget to set java 17. Just copy and paste the config below:
sudo nano /etc/systemd/system/tomcat.service
[Unit]
Description=Apache Tomcat Web Application Container
After=network.target
[Service]
Type=forking
WorkingDirectory=/opt/tomcat/webapps
Environment=JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment=CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC
Environment=JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/v/urandom
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
User=tomcat
Group=tomcat
UMask=0007
RestartSec=10
Restart=always
[Install]
WantedBy=multi-user.target
Let's start Tomcat server:
sudo systemctl daemon-reload
sudo systemctl start tomcat
sudo systemctl status tomcat
sudo systemctl enable tomcat
sudo ufw allow 8080
- open <IP_ADDRESS>:8080 from your browser
it's working
Now we have to add roles and users to manage our Tomcat application:
sudo nano /opt/tomcat/conf/tomcat-users.xml
copy and paste the config below:

<role rolename="tomcat"/>
<role rolename="admin-gui"/>
<role rolename="manager"/>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user username="admin" password="pass123" roles="tomcat,admin-gui,manager,manager-gui,manager-script,manager-jmx,manager-status"/>
Now allow remote access to Tomcat for each one. <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="^.*$" />
comment it using <!-- <something> -->
sudo nano /opt/tomcat/webapps/manager/META-INF/context.xml
sudo nano /opt/tomcat/webapps/host-manager/META-INF/context.xml

Restart Tomcat:
sudo systemctl daemon-reload
sudo systemctl restart tomcat

Deploy Java 17 Spring Boot 3 Application
To deploy our spring boot application we have to extend SpringBootServletInitializer. Extending it in Spring Boot allows the application to be deployed as a WAR on external servlet containers.
@SpringBootApplication
public class SpringBootDemoApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(SpringBootDemoApplication.class, args);
}
}
Update packaging type to war and specify build final name.
<name>spring-boot-demo</name>
<description>spring-boot-demo</description>
<!-- here -->
<packaging>war</packaging>
<properties>
<java.version>17</java.version>
</properties>
..........
<build>
<finalName>spring-boot-demo</finalName>
<plugins>
.........
Run the following command to build your project:
mvn clean package
Open tomcat manager <IP>:8080/manager/html and deploy your war file

Congrats


GitHub:
