WAR Packaging in Spring Boot
Fast recall
Quick revision
Core answer
Understanding of different deployment models and when enterprise constraints require traditional packaging
Dismissing WAR deployment as purely legacy — many large enterprises still mandate it for governance and operational reasons
Explain that Spring Boot can create a dual-mode WAR that works both as a WAR in external containers and as an executable JAR with embedded server
Interview-ready guide
Interview answer
You'd choose WAR packaging when you need to deploy to an external servlet container that's already installed and managed by your operations team.
This is still really common in enterprise environments.
For example, a bank might have a centralized WebSphere or JBoss installation where all internal applications run. The ops team manages that server infrastructure, handles security patches, and monitors everything through one console. In that scenario, they want you to provide a WAR file that they drop into their managed environment.
It's about centralized control. Modern cloud deployments prefer JAR packaging because it's self-contained. Your application brings its own embedded Tomcat, so you control the full stack.
You can version independently, deploy to Kubernetes easily, and don't depend on someone else's server infrastructure. But it's wrong to think WAR is dead. In regulated industries like finance or healthcare, there are often compliance requirements or governance policies that mandate application server deployments.
The operations team might need to demonstrate that all applications use a patched, approved version of Tomcat, which is easier with centralized deployment. One thing that's cool about Spring Boot is you can actually create a dual-mode WAR. xml, extend SpringBootServletInitializer in your main class, and the resulting WAR can work both ways.
You can deploy it to external Tomcat, or you can run it directly with java -jar like an executable JAR. This gives you flexibility if you're not sure which model you'll need.
A common mistake freshers make is assuming WAR is purely legacy and dismissing it. When you join an enterprise with existing infrastructure, you might find that WAR deployment is the standard, and you need to work within that model. The key is understanding when each approach makes sense based on your deployment environment and operational requirements.
WAR Packaging in Spring Boot
Direct Answer
Package a Spring Boot servlet application as a WAR when it must be deployed to an external compatible servlet container or application server. Use an executable JAR when the application owns its process and server dependency. A Boot WAR can also be executable, and reactive WebFlux applications are not deployed as traditional servlet WARs.
Common Mistakes & Pitfalls
- Dismissing WAR as obsolete: Freshers often think WAR is purely legacy and no one uses it anymore, but many large organizations have huge investments in WebSphere or JBoss infrastructure and require WAR packaging for all internal applications.
- Not knowing dual-mode WAR: Spring Boot can create a WAR that works both as a traditional WAR in external Tomcat and as an executable with java -jar — freshers miss this flexibility and think it's an either-or choice.
- Ignoring servlet initializer requirement: Converting to WAR packaging requires extending SpringBootServletInitializer in your main class — forgetting this means the WAR deploys but doesn't start correctly.
- Wrong packaging element: Keeping packaging=jar in pom.xml when trying to build a WAR, which produces an executable JAR instead of a proper WAR structure with WEB-INF directories.
Check your understanding
Answer these without looking back at the article.
- How do you configure packaging in pom.xml?
- What is SpringBootServletInitializer?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.