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

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

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

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

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

Related

  • Deploy Spring Boot Apps From Jar to War
  • A Practical Guide to Creating a Spring Modulith Project
  • Distributed Tracing System (Spring Cloud Sleuth + OpenZipkin)
  • Java, Spring Boot, and MongoDB: Performance Analysis and Improvements

Trending

  • Navigating Change Management: A Guide for Engineers
  • Building a Real-Time Audio Transcription System With OpenAI’s Realtime API
  • Analyzing Techniques to Provision Access via IDAM Models During Emergency and Disaster Response
  • Enhancing Business Decision-Making Through Advanced Data Visualization Techniques
  1. DZone
  2. Coding
  3. Frameworks
  4. Packaging and Deploying Spring Boot Applications as WAR Files

Packaging and Deploying Spring Boot Applications as WAR Files

This article is a tutorial on how to package and deploy Spring Boot applications as WAR files. Read on below to find out more.

By 
Alejandro Duarte user avatar
Alejandro Duarte
DZone Core CORE ·
Sep. 02, 21 · Tutorial
Likes (8)
Comment
Save
Tweet
Share
9.1K Views

Join the DZone community and get the full member experience.

Join For Free

Introduction

This guide explains how to do the following:

  • Package a Maven-based Spring Boot application as a WAR file.
  • Deploy a WAR file to Apache Tomcat.
  • Deploy a WAR file to Eclipse Jetty.

Packaging a Maven-Based Spring Boot Application as a WAR File

To change the packaging in a Maven-based Spring Boot application that was generated using the Spring Initializr or Vaadin Start tools, make the following changes in the pom.xml file:

1. Modify the <packaging> element as follows:

XML
 
<packaging>war</packaging>


2. If you plan to deploy to a different server than Apache Tomcat, follow this:

a) Add the Servlet API dependency to the project. Make sure to use the version that matches your project. For example, in the case of Vaadin applications:

XML
 
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
    <scope>provided</scope>
</dependency>


b) Exclude the spring-boot-starter-tomcat dependency from the spring-boot-starter-web dependency if you are using Spring MVC, or the vaadin-spring-boot-starter dependency if you are using Vaadin. For example:

XML
 
<dependency>
    <groupId>com.vaadin</groupId>
    <artifactId>vaadin-spring-boot-starter</artifactId>
    <exclusions>
        ...
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>


3. Optional: If you want to simplify the name of the WAR file and always build a file with the same name without version numbers, add the following to the <build> section:

XML
 
<finalName>${project.artifactId}</finalName>


4. Build and package the application by running the mvn package command. If you are using Vaadin, enable the production profile (mvn package -P production). You can find the WAR file in the target/ directory inside the Maven project.

Deploying a WAR File to Apache Tomcat

To deploy the application configured in the previous section to a local instance of Apache Tomcat:

  1. Download Apache Tomcat from the project website. Make sure to download the correct version, depending on the Java and Servlet API versions that your application uses. For example, in the case of Vaadin applications, download Apache Tomcat version 9.
  2. Extract the downloaded file.
  3. Start the server by running the start.sh or start.bat scripts that you can find in the bin/ directory inside the Apache Tomcat installation directory. You might have to add execute permissions to the script files in the bin/ directory. For example, in Unix-like operating systems, run chmod +x bin/*.sh.
  4. Copy the WAR file from the target/ directory inside your Maven project to the webapps/ directory inside the Apache Tomcat installation directory.
  5. The application should be deployed automatically and made available at http://localhost:8080/your-war-file-name. Use ROOT.war if you want to deploy to the context root (http://localhost:8080/).

Deploying a WAR File to Eclipse Jetty

To deploy the application previously configured to a local instance of Eclipse Jetty:

  1. Download Eclipse Jetty from the project website. Make sure to download the correct version, depending on the Java and Servlet API versions that your application uses. For example, in the case of Vaadin applications, download Eclipse Jetty 9.
  2. Extract the downloaded file.
  3. If you downloaded Eclipse Jetty 10, configure the server by running java -jar start.jar --add-module=server,http,deploy inside the Eclipse Jetty installation directory.
  4. Start the server by running start.sh start in the bin/directory inside the Eclipse Jetty installation directory. You might have to add execute permissions to the script files in the bin/ directory by running chmod +x bin/*.sh.
  5. Copy the WAR file from the target/ directory inside your Maven project to the web apps/directory inside the Eclipse Jetty installation directory.
  6. The application should be deployed automatically and made available here. Use root.war if you want to deploy to the context root.
Spring Framework application Spring Boot WAR (file format) Apache Tomcat

Published at DZone with permission of Alejandro Duarte. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Deploy Spring Boot Apps From Jar to War
  • A Practical Guide to Creating a Spring Modulith Project
  • Distributed Tracing System (Spring Cloud Sleuth + OpenZipkin)
  • Java, Spring Boot, and MongoDB: Performance Analysis and Improvements

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!