Spring Boot war Packaging Example

In Spring boot applications, default packaging is jar which is deployed in embedded servers. If you want to generate a war file for deployment in seperate application server instances such as Jboss, Weblogic or tomcat, then follow below instructions.

Step 1) Declare packaging type ‘war’

First logical step is to declare the packaging type ‘war’ in pom.xml file.

<project xmlns="http://maven.apache.org/POM/4.0.0"

It indicates the project’s artifact type. Please note that when no packaging is declared, Maven assumes the artifact is the default: jar.

Step 2) Set embedded server dependency scope to ‘provided’

We may want to have embedded server (e.g. tomcat) in development environment because of its usefulness in fast development lifecycle, but we certainly not want those server jars to be included in finally generated maven artifact or war file. To do so, set scope of embedded server dependency to ‘provided’.

Scope ‘provided’ indicates you expect the JDK or a container to provide the dependency at runtime. This scope is only available on the compilation and test classpath, and is not transitive.

Read more: Dependency Mechanism

War Packaging Demo

In this demo, we are using below pom.xml.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd;








			<name>Spring GA Repository</name>

Now run maven build with goal clean install and it will genearte the project’s war file in target folder as below.

Spring Boot War Packaging Example
Spring Boot War Packaging Example

Drop me your questions in comments section.

Happy Learning !!

Was this post helpful?

Join 8000+ Awesome Developers, Like YOU!

12 thoughts on “Spring Boot war Packaging Example”

  1. Hi Lokesh,

    Hope you are doing well!

    Any ideas on how to package an executable spring boot jar as war? I understand it will be a manual process configuration. The idea is to ship this in JBOSS as a war eventually.

    Thanks and Regards,

  2. do you know if it is possible to “update” a regular spring mvc application in spring boot application? because in spring boot we eliminate web.xml and xml configuration in favor of conventions of spring boot

  3. Hi,
    I created a boot project to create a war and trying to build that on jenkin and getting following error
    org.apache.maven.plugin.PluginResolutionException: Plugin org.springframework.boot:spring-boot-maven-plugin:2.0.0.RELEASE or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.springframework.boot:spring-boot-maven-plugin:jar:2.0.0.RELEASE.

    Please help me in resolving this issue

  4. Hi, i lost my all the packages of spring boot like classes and controller but i have the snapshot.jar file with me so it is possible to retrieve the packages from it??

  5. you will have to modify the main application class , It extends from SpringBootServletInitializer so that it can be deployed as a WAR.


    public class Application extends SpringBootServletInitializer {

    public static void main(String[] args) {
    SpringApplication.run(Application.class, args);

  6. You didn’t tell anything about the project structure, for instance where to put the WebContent and its subfolders, web-inf/web.xml file etc in the spring boot 2.x configuration


Leave a Comment

About HowToDoInJava

This blog provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions, and frequently asked interview questions.