DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Spring Boot Pet Clinic App: A Performance Study
  • Improving Backend Performance Part 1/3: Lazy Loading in Vaadin Apps
  • How to Activate New User Accounts by Email
  • Spring Config Integration With a PCF Application: A Step-by-Step Guide

Trending

  • AI's Dilemma: When to Retrain and When to Unlearn?
  • Secure by Design: Modernizing Authentication With Centralized Access and Adaptive Signals
  • Event-Driven Architectures: Designing Scalable and Resilient Cloud Solutions
  • IoT and Cybersecurity: Addressing Data Privacy and Security Challenges
  1. DZone
  2. Coding
  3. Frameworks
  4. Deploy Spring Boot Apps From Jar to War

Deploy Spring Boot Apps From Jar to War

In this article, see how to deploy Spring Boot apps from jar to war.

By 
Adiel Isaacs user avatar
Adiel Isaacs
·
Allen Coin user avatar
Allen Coin
·
Updated Jun. 24, 20 · Tutorial
Likes (10)
Comment
Save
Tweet
Share
37.9K Views

Join the DZone community and get the full member experience.

Join For Free

Make it Platform-Independent 

Developing Spring Boot applications could be easy these days with the likes of annotations and initializes as Maven, Spring Boot, and embedded servers. 

So as we know when building a Spring Boot application, by default, we package the application into a JAR file and execute our main application class into a main embedded tomcat server. We then run our application tests, web app, or REST endpoints within our environment for easy testing and debugging.

What if we want to make our application server independent and drop our application on other servers like Weblogic, Jboss, Wildfly, etc.?

In order to do this, we have to make our application a WAR file.  

Here are simple steps to do so:

1. Update your maven pom.xml with the following changes    

Set your packaging tag to war

Java
 




x


 
1
    <packaging>war</packaging>
2




Set all Tomcat Jar files to provided

Java
 




x


 
1
<dependency>
2
 <groupId>org.springframework.boot</groupId>
3
 <artifactId>spring-boot-starter-tomcat</artifactId>
4
 <scope>provided</scope>
5
</dependency>



Then, we need to update the maven-war-plugin ,  not to fail if web.xml is missing. This can be done by updating the plugin information in the build tag and by removing the  org.springframework.boot  plugin in the pom as shown below:

Java
 




xxxxxxxxxx
1
21


 
1
<plugins>
2
            <!--  <plugin>
3
                <groupId>org.springframework.boot</groupId>
4
                <artifactId>spring-boot-maven-plugin</artifactId>
5
            </plugin>
6
            -->
7
            <plugin>
8
            <groupId>org.apache.maven.plugins</groupId>
9
            <artifactId>maven-war-plugin</artifactId>
10
            <version>3.1.0</version>
11
            <executions>
12
                <execution>
13
                    <id>default-war</id>
14
                    <phase>prepare-package</phase>
15
                    <configuration>
16
                        <failOnMissingWebXml>false</failOnMissingWebXml>
17
                    </configuration>
18
                </execution>
19
            </executions>
20
        </plugin>
21
        </plugins>



2. Update your Main class to extends SpringBootServletInitializer    

Java
 




xxxxxxxxxx
1
13


 
1
@SpringBootApplication
2
public class SpringBootWarDeploymentApplication  extends SpringBootServletInitializer {
3
    
4
    @Override
5
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
6
        return application.sources(SpringBootWarDeploymentApplication.class);
7
    }
8
 
          
9
    public static void main(String[] args) {
10
        SpringApplication.run(SpringBootWarDeploymentApplication.class, args);
11
    }
12
}
13
 
          



3. Rename your file SpringBootWarDeployment-0.0.1.war to your desired name springrestapi.war

4. Check if your Server container has missing web.xml file capabilities 

We generally want version numbers out of our build files as certain containers fails to deploy dash versions.

Conclusion

This worked for me, generally, I downloaded Apache Tomcat 8.5 and edited the pom.xml plugin and viola! It worked. All my projects ended up working because Tomcat 8.5 and up accepted no Web.xml and the exclusion thereof.

Have fun, folks! 

Don't forget to like, comment, and share!

Spring Framework Spring Boot app Apache Tomcat JAR (file format) WAR (file format) application

Opinions expressed by DZone contributors are their own.

Related

  • Spring Boot Pet Clinic App: A Performance Study
  • Improving Backend Performance Part 1/3: Lazy Loading in Vaadin Apps
  • How to Activate New User Accounts by Email
  • Spring Config Integration With a PCF Application: A Step-by-Step Guide

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!