Hackforge Academy

Category: java

Deploying Spring Boot to AWS

Published on 16 Jul 2026

Explanation

Before deployment, package the Spring Boot application into an executable JAR file using Maven. This JAR contains the application and embedded Tomcat server.

Code:

mvn clean package

Explanation

Launch an AWS EC2 instance, connect to it using SSH, and install Java. The EC2 instance will host the Spring Boot REST API.

Code:

sudo apt update
sudo apt install openjdk-21-jdk

Explanation

Upload the generated JAR file to the EC2 instance using SCP or any file transfer tool.

Code:

scp target/student-api.jar ubuntu@EC2_PUBLIC_IP:/home/ubuntu/

Explanation

Run the Spring Boot application on the EC2 instance using the java -jar command. The embedded Tomcat server starts automatically.

Code:

java -jar student-api.jar

Explanation

Open the application port (for example, 8080) in the AWS Security Group. Clients can then access the REST API using the EC2 public IP address.

Code:

http://EC2_PUBLIC_IP:8080/students

๐Ÿš€ Learn Spring Boot with real-world projects

๐Ÿ’ก Build REST APIs step by step

๐Ÿง  Improve backend development skills

๐ŸŽฏ Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

๐Ÿ

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
โš›๏ธ

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community
โ˜•

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community