How do you deploy a WAR file to Apache Tomcat?
BeginnerHands-onJava builds (Maven, Gradle, JAR, WAR)
Answer
Short answer
Copy the .war into Tomcat's webapps/ folder. Tomcat automatically unpacks and deploys it, and the app becomes available at /<war-name>. You can also deploy through the Tomcat Manager web app/API, which pipelines often use.
Steps
# Install / start Tomcat
sudo tar -xzf apache-tomcat-10.1.x.tar.gz -C /opt && sudo mv /opt/apache-tomcat-10.1.* /opt/tomcat
/opt/tomcat/bin/startup.sh # listens on 8080
# Deploy
cp target/shop.war /opt/tomcat/webapps/
tail -f /opt/tomcat/logs/catalina.out # watch "Deployment of web application archive ... has finished"
curl http://localhost:8080/shop/
Rename to ROOT.war to serve it at /.
Through the Manager API (from a pipeline)
curl -u deployer:$TOMCAT_PASS -T target/shop.war \
"http://tomcat:8080/manager/text/deploy?path=/shop&update=true"
The user needs the manager-script role in conf/tomcat-users.xml.
Gotchas
- Tomcat 10+ uses Jakarta EE (
jakarta.*packages); older WARs built forjavax.*need Tomcat 9. - Restrict the Manager app to internal networks — it's a common attack target.
What to say in the interview
"Copy the WAR into webapps or use the Manager text API with a manager-script user; Tomcat explodes and deploys it at the context path. I check catalina.out for deployment errors and keep the Manager endpoint locked down."
All Build Tools (Java, Node.js, Python, .NET) questions Roadmap: Java apps: Maven, Gradle, JAR & WAR
More on Java builds (Maven, Gradle, JAR, WAR)
What is pom.xml and what is it used for?BeginnerHow do you build and run a Java project with Maven?BeginnerWhat is the difference between a JAR and a WAR file?BeginnerWhat is Gradle and how is it different from Maven?BeginnerHow do you configure a Spring Boot application for different environments?BeginnerA Maven build fails in the pipeline with "Could not resolve dependencies". How do you fix it?Intermediate