← Learning Hub
Advanced

Project: Package, Monitor and Deploy

You've built a shop API with products, orders, validation, a database, tests and security. Let's get it ready for a real server.

Getting an app into production means packaging it, monitoring its health and running it reliably. Spring Boot's runnable jar, Actuator health checks and Docker support make this straightforward.

1. Build a runnable jar

Example
./mvnw clean package            # runs the tests and builds target/shop-0.0.1-SNAPSHOT.jar
java -jar target/shop-0.0.1-SNAPSHOT.jar --spring.profiles.active=prod

The jar contains your code, all libraries and the web server - one file to run anywhere with Java.

2. Health checks and metrics: Actuator

Example
<!-- pom.xml -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Example
# application-prod.properties
management.endpoints.web.exposure.include=health,info
Example
curl http://localhost:8080/actuator/health
# {"status":"UP"}

Load balancers and Docker use /actuator/health to check the app is alive. Expose only what you need - some Actuator endpoints show sensitive details.

3. Put it in Docker

Example
FROM eclipse-temurin:21-jre
WORKDIR /app
COPY target/*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]
Example
./mvnw spring-boot:build-image          # or: let Spring Boot build an image for you, no Dockerfile needed

4. Run in production

  • Use PostgreSQL with Flyway migrations; pass DB_PASSWORD as an environment variable
  • Run behind Nginx with HTTPS (see the Linux + Docker course), or on AWS (Elastic Beanstalk, ECS or an EC2 server - see the AWS course)
  • Send logs somewhere you can search them, and watch error rates
  • Set memory for the JVM, e.g. JAVA_TOOL_OPTIONS=-XX:MaxRAMPercentage=75 in containers

Where to go next

  • Spring Boot's official guides at spring.io/guides
  • Caching with @Cacheable, scheduled jobs with @Scheduled, sending email
  • Microservices with Spring Cloud - only after you're comfortable with one app
  • Build the same API in Node.js (see that course) to compare the two styles
Key points
  • ./mvnw package builds a runnable jar.
  • Actuator exposes health checks.
  • Run in Docker or on a server behind HTTPS.

📝 Test yourself

1. What does ./mvnw clean package produce?
2. What is /actuator/health used for?
3. Fill in the command to run a jar:
java target/shop.jar