Skip to content

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

mecca register git@gitlab.com:appmecca-sample-apps/hello-java.git -e dev

2. Build the container

mecca build trigger -e dev -g git@gitlab.com:appmecca-sample-apps/hello-java.git
Expected output
Build started: build-xxxxxxxx
Cloning repository...
Building container: hello-java
Pushing image to the private registry: hello-java/web
Build complete. Duration: 85s

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

mecca app deploy -e dev hello-java
Expected output
Deploying hello-java to dev...
Deployment queued: deploy-xxxxxxxx
Waiting for agents...
Container started: hello-java-web
Health check passed: /health -> 200 OK
Deployment complete.

Services:
  web: https://hello-java-web.dev.appmecca.net

4. Verify

mecca app show hello-java -e dev

Test the endpoint:

curl https://hello-java-web.dev.appmecca.net/health
{"status": "healthy"}

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?