What is the difference between a JAR and a WAR file?
Short answer
Both are packaged Java applications. A JAR usually contains everything needed to run on its own — java -jar app.jar. A WAR is a web application meant to be deployed inside a separate web server like Apache Tomcat.
Explained in simple words
- A JAR (Java ARchive) is like a food truck: it carries its own kitchen. Modern Spring Boot JARs include an embedded web server (Tomcat), so you just start them.
- A WAR (Web ARchive) is like a chef who needs a restaurant kitchen to work in. You copy the WAR into an existing Tomcat server, and Tomcat runs it.
Comparison
| JAR | WAR | |
|---|---|---|
| Full name | Java ARchive | Web Application ARchive |
| How you run it | java -jar app.jar |
Copy into Tomcat's webapps/ folder |
| Web server | Embedded inside (Spring Boot) | Provided by an external server (Tomcat, JBoss, WebLogic) |
| Typical use | Microservices, containers, modern apps | Older enterprise web apps |
| In pom.xml | <packaging>jar</packaging> |
<packaging>war</packaging> |
Example — deploying each one
# JAR — start it directly
java -jar target/orders-service-1.0.0.jar
# WAR — deploy into Tomcat
cp target/shop.war /opt/tomcat/webapps/
/opt/tomcat/bin/startup.sh
# app is now at http://server:8080/shop
Inside a JAR you'll find compiled .class files and a META-INF/MANIFEST.MF that says which class to start. Inside a WAR you'll find a WEB-INF/ folder with classes, libraries and web.xml.
Why most companies use JARs today
With containers and Kubernetes, a self-contained JAR is simpler: one process per container, started with java -jar. No separate Tomcat to install, patch and configure.
What to say in the interview
"Both are Java packages. A JAR — especially a Spring Boot fat JAR — includes an embedded web server, so we run it directly with java -jar, which fits containers perfectly. A WAR is a web application that must be deployed into an external servlet container like Tomcat, by copying it into the webapps folder. Most new microservices use JARs; WARs are mostly found in older enterprise applications."
Follow-up questions you may get
- What is a fat JAR (uber JAR)? A JAR that includes all its dependency libraries inside it, so it runs anywhere with just Java installed.
- Where is Tomcat's deployment folder?
$CATALINA_HOME/webapps/; logs are in$CATALINA_HOME/logs/catalina.out.