Skip to main content

Prerequisites

  • A Zerops account
  • Basic knowledge of Java
  • Java and Maven/Gradle installed locally

Deploy from Recipe

1

Import the Project

Log in to Zerops GUI and click Import a project.
2

Paste the Configuration

project:
  name: my-first-java-app
services:
  - hostname: app
    type: java@21
    minContainers: 1
    maxContainers: 3
    buildFromGit: https://github.com/zeropsio/recipe-java-hello-world@main
    enableSubdomainAccess: true
3

Deploy

Click Import project and wait for compilation.
4

Access

Visit your subdomain URL.

Deploy Your Own Application

Step 1: Create Spring Boot Application

Create a simple REST API:
src/main/java/com/example/demo/DemoApplication.java
package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@SpringBootApplication
@RestController
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @GetMapping("/")
    public Map<String, String> hello() {
        Map<String, String> response = new HashMap<>();
        response.put("message", "Hello from Java on Zerops!");
        return response;
    }

    @GetMapping("/health")
    public Map<String, String> health() {
        Map<String, String> response = new HashMap<>();
        response.put("status", "healthy");
        return response;
    }
}

Step 2: Add zerops.yaml

zerops.yaml
zerops:
  - setup: app
    build:
      base: java@21
      buildCommands:
        - mvn clean package -DskipTests
      deployFiles:
        - target/*.jar
      cache: ~/.m2/repository
    
    run:
      start: java -jar target/demo-0.0.1-SNAPSHOT.jar
      ports:
        - port: 8080
          httpSupport: true
      envVariables:
        SPRING_PROFILES_ACTIVE: production

Step 3: Configure Service

description.yaml
project:
  name: my-java-app
services:
  - hostname: app
    type: java@21
    minContainers: 1
    maxContainers: 6
zcli project project-import description.yaml

Framework Examples

Spring Boot with Gradle

build.gradle.kts
plugins {
    java
    id("org.springframework.boot") version "3.2.0"
    id("io.spring.dependency-management") version "1.1.4"
}

group = "com.example"
version = "0.0.1-SNAPSHOT"

repositories {
    mavenCentral()
}

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-web")
    testImplementation("org.springframework.boot:spring-boot-starter-test")
}
zerops.yaml
build:
  buildCommands:
    - gradle build -x test
  deployFiles:
    - build/libs/*.jar
  cache: ~/.gradle/caches
run:
  start: java -jar build/libs/demo-0.0.1-SNAPSHOT.jar

Quarkus Application

zerops.yaml
zerops:
  - setup: api
    build:
      base: java@21
      buildCommands:
        - ./mvnw package -Dquarkus.package.type=uber-jar
      deployFiles:
        - target/quarkus-app/*.jar
    run:
      start: java -jar target/quarkus-app/quarkus-run.jar

Adding a Database

description.yaml
services:
  - hostname: app
    type: java@21
  - hostname: db
    type: postgresql@16
    mode: NON_HA
Configure in application.properties:
spring.datasource.url=jdbc:postgresql://db:5432/${DB_NAME}
spring.datasource.username=${DB_USER}
spring.datasource.password=${DB_PASSWORD}
spring.jpa.hibernate.ddl-auto=update

JVM Optimization

run:
  start: |
    java \
      -Xmx1g \
      -Xms512m \
      -XX:+UseG1GC \
      -XX:MaxGCPauseMillis=200 \
      -XX:+UseContainerSupport \
      -XX:MaxRAMPercentage=75.0 \
      -jar target/app.jar

Troubleshooting

Ensure Maven/Gradle wrapper is committed:
git add mvnw mvnw.cmd .mvn/
Check your artifact name:
deployFiles:
  - target/myapp-*.jar

Next Steps

Runtime Overview

Learn about Java runtime

Scaling

Configure auto-scaling

Build docs developers (and LLMs) love