Hello Java¶
A minimal Spring Boot web application in Java. Multi-stage Docker build with Gradle and JRE. One container, one service, no database, no cache.
Overview¶
| Repository | git@gitlab.com:appmecca-sample-apps/hello-java.git |
| Tech Stack | Java 21 / Spring Boot / Gradle |
| Services | web (port 8080) |
| Database | None |
| Cache | None |
| URL Pattern | https://hello-java-web.{env}.appmecca.net |
What This App Demonstrates¶
- Deploying a Java application on AppMecca
- Multi-stage Docker build (Gradle + JRE Alpine)
- Single-container deployment workflow
- Health check endpoint pattern
appmecca.yaml¶
containers:
- name: hello-java
dockerfile: Dockerfile
context: .
deploy:
- name: web
container: hello-java
port: 8080
health_check:
path: /health
The configuration is identical in structure to any other single-container app. Spring Boot listens on port 8080 by default.
Step-by-Step Deployment¶
1. Register the app¶
2. Build the container¶
Expected output
Java builds are slower than scripted languages because the Gradle build must download dependencies and compile the source code. Subsequent builds with cached Docker layers are faster.
3. Deploy¶
Expected output
4. Verify¶
Test the endpoint:
Key Concepts¶
Multi-stage Docker builds for Java¶
The Dockerfile compiles the application with Gradle and JDK 21 in the first stage, producing a fat JAR. The second stage uses Eclipse Temurin JRE 21 Alpine -- a lightweight runtime that does not include the compiler or build tools.
Image size comparison
| Stage | Image size |
|---|---|
gradle:8.12-jdk21 (build stage) |
~800 MB |
| Final image (JRE Alpine + JAR) | ~200 MB |
Spring Boot¶
Spring Boot is the standard Java web framework for building REST APIs and microservices. It auto-configures an embedded Tomcat server and provides production-ready features like health indicators, metrics, and externalized configuration.
Any language, same workflow
AppMecca does not care what language your application is written in. As long as your container listens on the declared port and responds to health checks, the deployment workflow is identical.
What's Next?¶
- Hello Flask -- see the same pattern in Python
- Go Web Server -- see the same pattern in Go
- Hello Dotnet -- see the same pattern in C#
- App with Database -- add PostgreSQL to your application