
Play Store Application link β Spring Boot in 13 steps – App on Google Play
Step 1: Setting Up a Spring Boot Project
Using Spring Initializr
- Visit https://start.spring.io/.
- Configure the project:
- Project: Maven
- Language: Java
- Spring Boot Version: 3.x.x
- Dependencies: Spring Web, Spring Boot DevTools
- Click Generate to download the project ZIP and extract it.
Import into IDE
- Import the project into your favorite IDE (IntelliJ, Eclipse, etc.) as a Maven project.
Step 2: Packaging Spring Boot Application as JAR/WAR
JAR Packaging (Default)
By default, Spring Boot creates a JAR file. To build your JAR, run the following Maven command:
./mvnw clean package
This will generate a .jar
file in the target/
directory.
WAR Packaging
To deploy your Spring Boot application as a WAR (for example, to a Tomcat server), update the pom.xml
file:
- Change the packaging type to
war
:
<packaging>war</packaging>
- Update the main class to extend
SpringBootServletInitializer
:
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
- Build the WAR file:
./mvnw clean package
Step 3: Deploying Spring Boot on Tomcat Server
Deploying JAR to Tomcat
- For WAR files, copy the
target/*.war
file to thewebapps/
directory of your Tomcat server. - For JAR files, run it directly from the command line:
java -jar target/demo-0.0.1-SNAPSHOT.jar
Hereβs a shorter, simpler version of the note:
Additional Note:
If you’re curious about how Docker and Kubernetes improve deployment, check out these posts:
We’ll cover Docker and Kubernetes in more detail in separate sections later.
Hereβs a quick comparison of the deployment methods:
- Manual Deployment: Done manually, slow, and hard to scale.
- Docker Deployment: Packages the app with its dependencies, making it portable and easier to deploy.
- Kubernetes Deployment: Automatically manages and scales Docker containers for better reliability and efficiency.
Conclusion
In this guide, we covered:
- Packaging Spring Boot applications as JAR/WAR files.
- Deploying on server (Tomcat)