How do you deploy a Spring Boot web application as a JAR or WAR file?

Spring Boot applications can be deployed as executable JAR files with an embedded server or as WAR files for deployment on an external servlet container. The choice depends on the deployment environment and infrastructure requirements.

Key Points

Example

Consider an Order Management application.

JAR Deployment

WAR Deployment

JAR Deployment Process

1. Configure packaging in pom.xml

<packaging>jar</packaging>

2. Build the application

mvn clean package

3. Run the generated JAR

java -jar target/order-service.jar

Spring Boot automatically starts the embedded server and deploys the application.

Advantages of JAR Deployment

WAR Deployment Process

1. Configure packaging in pom.xml

<packaging>war</packaging>

2. Extend SpringBootServletInitializer

@SpringBootApplication
public class Application
        extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(
            SpringApplicationBuilder application) {
        return application.sources(
                Application.class);
    }
}

3. Mark embedded Tomcat as provided

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>
        spring-boot-starter-tomcat
    </artifactId>
    <scope>provided</scope>
</dependency>

4. Build the WAR file

mvn clean package

5. Deploy the generated WAR file into

Comparison

JAR Deployment

WAR Deployment

Real-World Example

Microservices Architecture

Traditional Enterprise Portal

Best Practices

Interview Tip

A concise interview answer is: Spring Boot applications can be deployed as executable JAR files or traditional WAR files. JAR deployment uses an embedded server and is the preferred choice for modern microservices and cloud environments, while WAR deployment is used when applications need to run inside external servlet containers such as Tomcat or JBoss.

Last updated: 11 November 2026

Previous question: How do you make a Spring Boot auto-configuration back away when a bean already exists?

Next question: What does it mean that Spring Boot supports relaxed binding?

More Spring Boot - Level II interview questions

All Spring Boot - Level II questions