On this page

Java

Guara Cloud fully supports Java applications, including frameworks like Spring Boot, Quarkus, Micronaut, and any Maven or Gradle-based project.

Supported versions

The following Java versions are auto-detected:

  • Java 17 (LTS)
  • Java 21 (LTS)

The version is auto-detected from your pom.xml (Maven) or build.gradle (Gradle) configuration.

<!-- pom.xml -->
<properties>
    <java.version>21</java.version>
</properties>

Deploy with Dockerfile

A multi-stage build is the recommended approach for Java applications. It compiles your application with the full JDK, then runs it using only the JRE.

FROM maven:3.9-eclipse-temurin-21 AS build

WORKDIR /app

COPY pom.xml .
RUN mvn dependency:go-offline

COPY src ./src
RUN mvn package -DskipTests

FROM eclipse-temurin:21-jre-alpine

WORKDIR /app
COPY --from=build /app/target/*.jar app.jar

EXPOSE 3000

CMD ["java", "-jar", "app.jar"]

Deploy with Buildpack

If your repository does not contain a Dockerfile, Guara Cloud automatically detects your Java project by the presence of a pom.xml or gradlew file.

The auto-detection will:

  1. Detect the JDK version from your project configuration (pom.xml or build.gradle)
  2. Build your project with Maven or Gradle
  3. Auto-detect and run the Spring Boot JAR if present
  4. Start the application

Port configuration

Your application must listen on the port configured in your service settings. The default is 3000, but you can change it at any time to match your application.

For Spring Boot, configure it in application.properties:

server.port=${PORT:3000}

For Quarkus, use application.properties:

quarkus.http.port=${PORT:3000}

Example project structure

my-java-app/
  pom.xml
  Procfile
  src/
    main/
      java/
        com/example/
          Application.java
      resources/
        application.properties
  Dockerfile          # optional — omit to use Buildpack

Environment variables

These environment variables are commonly used with Java deployments:

VariableRecommended valueDescription
PORTSet by platformThe port your application must listen on
JAVA_OPTS-Xmx512mJVM memory and performance flags
SPRING_PROFILES_ACTIVEproductionActivates the production Spring profile

Common pitfalls