EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Software Development Software Development Tutorials Spring Tutorial Spring Boot War
 

Spring Boot War

Updated April 1, 2023

Spring Boot War

 

 

Definition of Spring Boot War

Spring boot war is defined as creating packaging of application as a war file. As we know that default packaging of the application is jar is deployed on tomcat server. We can also generate war file deployment of spring boot applications by using tomcat, JBoss, and weblogic server instances. To create or convert jar file into war packaging file of spring boot application we need to declare packaging type as war.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

Overview

  • It uses the tomcat server which makes to run our web application easily. By default, application code and libraries are packaged in a jar file.
  • To convert the executable jar file into the executable war file we need to follow the below steps are as follows.

1) First we need to disable tomcat server in the application.
2) After disabling tomcat server next step is to change the package type from jar to war file.
3) After changing package type next step is to extend the main application class of servlet initializer.
4) After initializing main class next or final step is to upload the project war file into the webapps directory of tomcat       server.

  • To disable the tomcat server in the application we need to tell tomcat server not to use the tomcat as servlet container. To disable the tomcat server, we need to add the starter tomcat dependency in pom.xml file of the application.
  • To change the packaging type of the application from jar to war file we need to change the packaging type of application as war in pom.xml file.
  • This application contains the main method which was used to run or launch the application. To extend the SpringBootServletInitializer in the main application class we need to modify the class and need to extend the SpringBootServletInitializer and after that, we need to configure override method. It will making the application is compatible while running inside into the servlet container.
  • To build the war file using maven we need to execute the below commands are as follows.
# mvn clean package
  • To build the war file using gradle we need to execute the below commands are as follows.
# gradle war
  • To upload the war file into the tomcat server we need to upload the war file into webapps directory of tomcat server.
  • In this application jar file with embedded server solution is not suitable for all the production-ready environments because deployment team wants full control on server, they are not touching any code so we need war file of the application.
  • Spring boot webflux is not depends on application and servlet API which was deployed on netty server, project war file deployment is not supported by webflux applications.
  • Extending the main class and configure the package war file are the main steps to create project war file in the application.
  • We can generate spring boot application war file to deploy inside containers. Maven plugin is supporting to create war file of the maven project.
  • The gradle plugin is supporting to create war file of gradle project. We can create a war file of our application using the gradle plugin.

Create WAR File Spring Boot

Below examples shows to create war file of the project are as follows.

1) Create project template using spring initializer and give name to project –

In the below step, we have provided project group name as com. example, artifact name as springbootWar, project name as springbootWar, and selected java version as 8.

Group – com.example Artifact name – springbootWar
Name – springbootWar Description – Project for springbootWar
Spring boot – 2.5.5 Project – Maven project
Java – 8 Package name – com.example.springbootWar Dependencies – spring web.

Spring Boot War 9

2) After generating project extract files and open this project by using spring tool suite –

Spring Boot War 10

3) After opening project using spring tool suite check the project and its files –

Spring Boot War 11

4) Add dependency packages –

Code:

<dependency> -- Start of dependency tag.
<groupId>org.springframework.boot</groupId> -- Start and end of groupId tag.
<artifactId>spring-boot-maven-plugin</artifactId> -- Start and end of artifactId tag.
</dependency> -- End of dependency tag.

Spring Boot War 12

5) Extend the main class –

Code:

@SpringBootApplication
public class warapp extends SpringBootServletInitializer{
public static void main/* main method of spring boot war app */ (String[] args)
{
SpringApplication.run (warapp.class, args);
}
}

Spring Boot War 13

6) Override the configure method –

Code:

@SpringBootApplication
public class warapp extends SpringBootServletInitializer
{
public static void main/* main method of spring boot war app */ (String[] args)
{
SpringApplication.run (warapp.class, args);
}
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder)
{
return builder.sources (warapp.class);
}
}

14

7) Configure the packaging war –

Code:

<packaging>war</packaging> -- Start and end of packaging tag.

15

8) Build the spring boot war project –

16

Spring Boot Examples

Below example shows spring boot using packaging as war file are as follows.

1) Create project template using spring initializer and give name to project –

In the below step we have provided project group name as com. example, artifact name as springboot_war, project name as springboot_war, and selected java version as 8.

Group – com.example
Artifact name – springboot_war
Name – springboot_war
Description – Project for springboot_war
Spring boot – 2.5.5
Project – Maven project
Java – 8
Package name – com.example.springboot_war
Dependencies – spring web.

17

2) After generating project extract files and open this project by using spring tool suite –

18

3) After opening project using spring tool suite check the project and its files –

19

4) Create simple class for spring boot war application –

Code:

public class springbootwar
{
public static void main /* main method of spring boot war application */ (String[] args)
{
SpringApplication.run (springbootwar.class, args);
System.out.println ("Simple code of spring boot war application");
}
}

20

5) Run the spring boot application using war file –

21

Conclusion

Spring boot uses the tomcat server which makes to run our web application easily. By default, application code and libraries are packaged in a jar file. Spring boot war is defined as to create packaging of application as war file.

Recommended Articles

This is a guide to Spring Boot War. Here we discuss definition, overviews, Create WAR File Spring Boot, examples with code implementation. You may also have a look at the following articles to learn more –

  1. Spring Boot Advantages
  2. Spring Boot Cache
  3. Spring Boot Initializr
  4. Spring Boot Maven

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

🚀 Limited Time Offer! - ENROLL NOW