The Java runtime

Note: SomeJava runtimes have reachedend of support. You cannot re-deployversions that use runtimes after their end of support date. We recommend thatyouupgrade your appto use the latest version of Java.

The Java runtime is the software stack responsible forinstalling your application code and dependencies, and then running thatapplication in the flexible environment.

Java versions

Java 25 usesbuildpacks. buildpacks help youbuild and configure containers that you can deploy to Google Cloud.

For the full list of supported Java versions, and theircorresponding Ubuntu version, see theRuntime support schedule.

To use asupportedJava version, you must:

Previous runtime versions

Warning: Java 8 has reached end of support.We recommend that you migrate your app to use asupported version of Java.

ForJava 8, specifyruntime_config andjdk settings in yourapp.yaml file.

Java 8 supports:

  • The Eclipse Jetty 9 runtime and runs Jetty 9 using Servlet 3.1.

  • Your own server code that listens on port 8080 as part of yourapplication. This feature lets you to use microservice frameworks likeSparkJava andSpring-Boot.

Examples

  • Specifying Jetty version 9 (default / optional):

    runtime_config:jdk:openjdk8server:jetty9
  • Specifying Java version 8:

    runtime_config:jdk:openjdk8
  • Sampleapp.yaml for Java 8:

    runtime:javaenv:flexhandlers:-url:/.*script:this field is required, but ignored

Seepom.xmlfor configuring Maven andbuild.gradlefor configuring Gradle.

Optional files

These configuration files are optional:

Place these files at the top level of MyDir. If you use any these files, youmust deploy them separately with thegcloud app deploy command.

web.xmlis optional and only needed if you are not using Servlet 3.x annotations.

You can place static web content, as well as your JavaServer pages, in yourwebapp/ directory.Jetty 9, which theApp Engine flexible environment uses as its Servlet container, uses Apache Jasperas the default JSP implementation and includes JSTL taglibs.

The Dockerfile file is optional and used tocustomize theJava runtime.

Enabling gzip compression

Thegzip handler is bundled with Jetty but not activated by default. Toactivate this module, set the environment variable,JETTY_MODULES_ENABLE=gzip,in theapp.yaml file:

env_variables:JETTY_MODULES_ENABLE:'gzip'

Using Quickstart

Jettycan speed upthe start time of your application by pre-scanning its content and generatingconfiguration files.If you are using anextended imageyou can activate quickstart by executing/scripts/jetty/quickstart.sh in yourDockerfile, after the application WAR is added.

Environment variables

You can set the following optional environment variables that are specific tothe Java 8/Jetty 9 runtime. You can set OpenJDK 8 environment variables as well.

To set environment variables, use theenv_variables key in theapp.yamlfile.

Env VarMaven PropValue/Comment
JETTY_PROPERTIESComma separated list ofname=value pairs appended to$JETTY_ARGS
JETTY_MODULES_ENABLEComma separated list of modules to enable by appending to$JETTY_ARGS
JETTY_MODULES_DISABLEComma separated list of modules to disable by removing from$JETTY_BASE/start.d
JETTY_ARGSArguments passed to jetty'sstart.jar. Any arguments used for custom jetty configuration should be passed here.
JAVA_OPTSJVM runtime arguments

Enhanced Cloud Logging (Beta)

When running on the App Engine flexible environment, you can configure Java UtilLogging to send logs to Cloud Logging by setting theJETTY_ARGS environment variable. For example:

env_variables:JETTY_ARGS:-Djava.util.logging.config.file=WEB-INF/logging.properties

You must provide alogging.properties file that configures aLoggingHandleras follows:

handlers=com.google.cloud.logging.LoggingHandler#Optionalconfiguration.level=INFOcom.google.cloud.logging.LoggingHandler.level=FINEcom.google.cloud.logging.LoggingHandler.log=gae_app.logcom.google.cloud.logging.LoggingHandler.formatter=java.util.logging.SimpleFormatterjava.util.logging.SimpleFormatter.format=%3$s:%5$s%6$s

Support for other Java runtimes

If you need to use a Java version that isn'tsupported, you can create acustom runtime and select avalid base image with the Java version you need.

For Google-supplied base images orDocker Java base images,seeBuilding custom runtimes.

Organizing your files

Your source tree should look like this:

MyDir/  [pom.xml]  [build.gradle]  [index.yaml]  [cron.yaml]  [dispatch.yaml]  src/main/    appengine/      app.yaml    docker/      [Dockerfile]    java/      com.example.mycode/        MyCode.java    webapp/      [index.html]      [jsp.jsp]      WEB-INF/        [web.xml]

Local testing

When testing in your local environment, you may use emulated Google Cloudservices, rather than remote Google Cloud services. You can use the followingemulators:

Use thegcloud command to start them before you run your app:

gcloudbetaemulatorsdatastorestartgcloudbetaemulatorspubsubstartgcloudbetaemulatorsbigtablestart

Maven

Add these lines in your mavenpom.xml file to add the Jetty 9 Maven Plugin:

<plugin><groupId>org.eclipse.jetty</groupId><artifactId>jetty-maven-plugin</artifactId><version>9.4.2.v20170220</version></plugin>

To run your app locally, use the Maven command:

mvnjetty:run-exploded

Gradle

Follow theCreating a new Gradle projectinstructions to add the Gretty Gradle pluginto yourbuild.gradle, and use the command:

gradlejettyRun

Deploy your app

To initialize the Google Cloud CLI, run:

gcloudinit

After completing the configurations, you can use the Google Cloud CLI to deploythis directory containing theapp.yaml and WAR files using:

gcloudappdeployapp.yaml

If you are using any of the optional configuration files (index.yaml,cron.yaml, anddispatch.yaml) deploy them separately with thegcloudcommand. For example:

gcloudappdeploycron.yaml

Maven

UseMaven to deploy your app:

mvn package appengine:deploy -Dapp.deploy.projectId=PROJECT_ID

ReplacePROJECT_ID with the ID of your Google Cloud project. Ifyourpom.xml file alreadyspecifies yourproject ID, you don't need to include the-Dapp.deploy.projectId property in thecommand you run.

Gradle

UseGradle to deploy your app:

gradleappengineDeploy

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-19 UTC.