Create a Deployable WAR File with Spring Boot

When building RESTful Web Services with Spring Boot, we can either package our Spring Boot App as an executable JAR file and run it with built-in Tomcat, or we can create a deployable WAR file and then deploy it into a stand along Tomcat or Jetty. With this blog post, I will share how to edit your Spring Boot app so that when built with Maven, it generates a deployable WAR file which you can use to deploy your application into a Tomcat or Jetty, for example.

If you are interested in learning how to download and install Tomcat and also how to deploy your WAR file to a Tomcat running either on your local machine or on a remote Linux server, check out my other video lessons on “RESTful Web Services with Spring Boot, Spring MVC, JPA, and MySQL”.

Creating a Deployable WAR File

1) Extend the SpringBootServletInitializer

To make your Spring Boot Web App work as a deployable WAR file, we will need to:

  • Open Java class that contains the public static void main(String[] args) and make it extend the SpringBootServletInitializer class
  • Call the application.sources(DeployableWarApplication.class) method as in the example below. Where the DeployableWarApplication.class is the class which contains the public static void main(String[] args) method.
package com.appsdeveloperblog.DeployableWar;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;

public class DeployableWarApplication extends SpringBootServletInitializer {

 public static void main(String[] args) {, args);
 protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
  return application.sources(DeployableWarApplication.class);


2) Set Project Packaging to a WAR

Open the POM.xml file of your project and update the <packaging> XML element to have the value of WAR rather than JAR.


3) Add spring-boot-starter-tomcat to POM.XML

The next step is to add a new spring-boot-started-tomcat dependency to a pom.xml file of your project. Have a look at the example dependencies from my pom.xml file.

Please note that the <scope> XML element of spring-boot-starter-tomcat contains the value provided.



And this is it! Now you should be able to clean and build the project with the below commands.

First, clean the project:

maven clean

and now build your project to generate a deployable WAR file:

mvn install

After the successful build of your project, check the target/ folder. It should now contain the deployable WAR file.

I hope this short blog post is of some value to you. Check out my other blog posts on Building RESTful Web Services with Spring Boot. Also, if you prefer to learn by watching a step by step video lessons, check the below list of video courses; maybe one of them will help you take your skills to a whole new level.

Leave a Reply

Your email address will not be published.