EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials Spring Tutorial Spring Boot War
Secondary Sidebar
Spring Tutorial
  • Spring Boot
    • What is Spring Boot
    • Spring Boot flyway
    • Spring Boot framework
    • Spring Boot Logback
    • Spring Boot actuator endpoints
    • Spring Boot gRPC
    • Spring Boot jdbctemplate example
    • Spring Boot ehcache
    • Spring Boot Architecture
    • Spring Boot Port
    • Introduction of spring boot
    • Spring Boot ide
    • Spring Boot Netty
    • Spring Boot ORM
    • Spring Boot Versions
    • Spring Boot JUnit
    • Spring Boot Keycloak
    • Spring Boot gradle
    • Spring Boot Lombok
    • Spring Boot autowired
    • Spring Boot bean
    • Spring Boot hibernate
    • Spring Boot integration test
    • Spring Boot jdbc
    • Spring Boot MongoDB
    • Spring Boot postgresql
    • Spring Boot rest
    • Spring Boot swagger
    • Spring Boot thymeleaf
    • Spring Boot Unit Test
    • Spring Boot Webflux
    • Spring Boot webclient
    • Spring Boot kubernetes
    • Spring Boot Properties
    • Spring Boot Validation
    • Spring Boot Feature
    • Spring Boot Application
    • Spring Boot email
    • Spring Boot MVC
    • Spring Boot Exception Handling
    • Spring Boot Starter Parent
    • Spring Boot Docker
    • Spring Boot Logging
    • Spring Boot Query
    • Spring Boot Multiple Data Sources
    • Spring Boot Basic Authentication
    • Spring Boot Test
    • Spring Boot jwt
    • Spring Boot Liquibase
    • Spring Boot Prometheus
    • Spring Boot debug
    • Spring Boot GraalVM
    • Spring Boot Batch
    • Spring Boot controller
    • Spring Boot CLI
    • Spring Boot file upload
    • Spring Boot interceptor
    • Spring Boot Service
    • Spring Boot Configuration
    • Spring Boot Datasource Configuration
    • Spring Boot Annotations
    • Spring Boot Starter We
    • Spring Boot Actuator
    • Spring Boot DevTools
    • Spring Boot Repository
    • Spring Boot Dependencies
    • Spring Boot Path Variable
    • Spring Boot Microservices
    • Spring Boot Run Command
    • Spring Boot application.properties
    • Spring Boot Transaction Management
    • Spring Boot Banner
    • Spring Boot JPA
    • Spring Boot Change Port
    • Spring Boot RestTemplate
    • Spring Boot cors
    • Spring Boot HTTPS
    • Spring Boot OAuth2
    • Spring Boot Profiles
    • Spring Boot Interview Questions
    • Spring Boot filter
    • Spring boot logging level
    • Spring Boot Cache
    • Spring Boot Advantages
    • Spring Boot Scheduler
    • Spring Boot Initializr
    • Spring Boot Maven
    • Spring Boot Admin
    • Spring Boot Tomcat
    • Spring Boot WebSocket
    • Spring Boot Executable Jar
    • Spring Boot CommandLineRunner
    • Spring Boot DataSource
    • Spring Batch Scheduler
    • Spring Batch Example
    • Spring Batch Tasklet
    • Spring Batch Admin
    • Spring Batch
    • Spring Boot Qualifier
    • Spring Boot War
    • Spring Boot Test Configuration
  • Spring
    • What is Spring Framework?
    • Spring Architecture
    • What is Spring Integration?
    • IoC Containers
    • What is AOP?
    • Spring Modules
    • Spring Batch Processing
    • Spring Batch Partitioner
    • Spring Batch Job
    • Spring AOP
    • Spring Expression Language
    • Dependency Injection in Spring
    • Spring Batch Architecture
    • Spring framework Interview Questions
  • Spring Cloud Basics
    • What is Spring Cloud
    • Spring Cloud Contract
    • Spring Cloud Components
    • Spring Cloud Version
    • Spring Cloud Data Flow
    • Spring cloud stream
    • Spring Cloud Dependencies
    • Spring cloud microservices
    • spring cloud gateway
    • Spring Cloud Config
    • Spring Cloud Kubernetes
    • Spring Cloud Sleuth

Related Courses

Spring Boot Certification Course

Spring Framework Course Training

All in One Data Science Course

Spring Boot War

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.

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

All in One Software Development Bundle(600+ Courses, 50+ projects)
Python TutorialC SharpJavaJavaScript
C Plus PlusSoftware TestingSQLKali Linux
Price
View Courses
600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (86,754 ratings)
  • To build the war file using gradle we need to execute the below commands are as follows.

# gradle war

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

  • 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
Popular Course in this category
Spring Boot Training Program (2 Courses, 3 Project)
  2 Online Courses |  3 Hands-on Projects |  22+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

Spring Framework Training (4 Courses, 6 Projects)4.9
All in One Data Science Bundle (360+ Courses, 50+ projects)4.8
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

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

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

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

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

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

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

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

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more