Java runtime environment

The Java runtime is the software stack responsible for installingyour web service's code and its dependencies and running your service.

Declare the Java runtime for the App Engine standard environment in theapp.yaml file. For example:

runtime:javaVERSION

WhereVERSION is the JavaMAJOR version number. Forexample, to use the latest Java version, Java 25 (preview), specify25.

For other supported Java versions, and the corresponding Ubuntu version for yourJava version, see theRuntime support schedule.

Before you begin

  1. Download the latest version of theGoogle Cloud CLIor update your gcloud CLI to the current version:

    gcloudcomponentsupdate
  2. To deploy using Maven, you will need to add theApp Engine Maven Pluginto yourpom.xml file:

    <plugin><groupId>com.google.cloud.tools</groupId><artifactId>appengine-maven-plugin</artifactId><version>2.8.1</version></plugin>

    Other options for deploying include using thegcloud app deploy command ortheApp Engine Gradle plugin.

  3. Follow the instructions for your application framework to configure the buildof an executableJAR file.

Framework compatibility

With the App Engine Java runtime, you can deploy executable JARfiles. The runtimes do not include any web-serving framework, meaning you are not limited tousing servlet-based frameworks or libraries. Use your native dependencies ornetworking stacks such as theNetty library.

You are not limited to these frameworks and are encouraged to try yourpreferred one, like Grails, Blade, Play!, Vaadin orjHipster.

Deploy Maven source projects to the Java runtime

You can deploy your Maven project as source code and have it built and deployedusingGoogle Cloud's buildpacks.

To deploy a Maven project project as source code, go to your project's top leveldirectory and type:

gcloudappdeploypom.xml

Build and deploy logs will be streamed, and you can see the detailed logs in theCloud Build history section in theGoogle Cloud console.

Using GraalVM executables

The App Engine standard environment Java runtime supports GraalVM native imageexecutables. Once you have compiled your Java app into a GraalVM nativeimage, you can use theentrypoint setting in yourapp.yaml fileto point to the executable.

For example, an executable with the filenamemyexecutable could have thefollowingapp.yaml configuration file:

runtime:25# or another supported runtime version.entrypoint:./myexecutable

Google Cloud client libraries can be used to compile applications asa GraalVM native image. For more information, refer to documentation on how toCompile native images.

Java version

The latest supported Java version is 25 (preview). The Java runtime uses the latest stable release of the version thatis specified in yourapp.yaml file. App Engine automatically updatesto new patch release versions, but it won't automatically update the minorversion.

For example, your application might be deployed at Java 21.0.4 andautomatically updated to version Java 21.0.5 at a later deployment of themanaged platform, but it won't be automatically updated to Java 22.

To learn how to upgrade your version of Java, seeUpgrade an existing application.

The runtime's Open JDK environment

App Engine runs Java apps in a container secured by gVisor on anup-to-date Ubuntu Linux distribution and its supported openjdk-17-jdk for Java 17 or openjdk-21-jdk for Java 21 runtime.

For supported Ubuntu versions for your Java version, seeRuntime support schedule.

App Engine maintains the base image and updates theOpenJDK 17 and OpenJDK 21 package, without requiring you to redeploy your app.

Your deployed app is located in the runtime's/workspace directory. It isalso accessible through a symbolic link at/srv.

App Engine Java releases

All released artifacts that start with version2.x.x use theopen sourcerelease mechanism. See theGitHub repository for more details.

Dependencies

For more information on declaring and managing dependencies, seeSpecifying dependencies.

Application startup

Frameworks such as Spring Boot, Micronaut, Ktor build an executable uberJARby default. If your Maven or Gradle build file produces an executable Uber JAR,the runtime starts your application by running an Uber JAR application.

Alternatively, App Engine will use the contents of the optionalentrypoint field in yourapp.yaml file. For example:

runtime:java25# or another supported runtimeentrypoint:java-Xmx64m-jarYOUR-ARTIFACT.jar

Where the exampleYOUR-ARTIFACT.jar application jar must:

  • Be in the root directory with yourapp.yaml file.
  • Contain aMain-Class entry in itsMETA-INF/MANIFEST.MF metadata file.
  • Optionally, contain aClass-Path entry with a list of relative paths toother dependent jars. These will upload with the application automatically.

For your app to receive HTTP requests, your entrypoint should start a web serverthat listens on the port specified by thePORT environment variable. The valueof thePORTenvironment variableis dynamically set by the App Engine serving environment. This valuecannot be set in theenv_variables section of theapp.yaml file.

With a custom entrypoint, you can construct and package your application as athin JAR file which only contains your application code and directdependencies. When deploying your application, the AppEngine plugin will only upload the files that changed, rather than the entireuber JAR package.

Be sure to use the PORT environment variable

If you see the warnings about port 8080 and NGINX in your app log files, yourapp's web server is listening on the default port 8080. This preventsApp Engine from using its NGINX layer to compress HTTP responses. Werecommend that you configure your web server respond to HTTP requests on theport specified by thePORT environment variable, typically 8081. For example:

/* * Copyright 2019 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */packagecom.example.appengine;importcom.sun.net.httpserver.HttpServer;importjava.io.IOException;importjava.io.OutputStream;importjava.net.InetSocketAddress;publicclassMain{publicstaticvoidmain(String[]args)throwsIOException{// Create an instance of HttpServer bound to port defined by the// PORT environment variable when present, otherwise on 8080.intport=Integer.parseInt(System.getenv().getOrDefault("PORT","8080"));HttpServerserver=HttpServer.create(newInetSocketAddress(port),0);// Set root URI path.server.createContext("/",(vart)->{byte[]response="Hello World!".getBytes();t.sendResponseHeaders(200,response.length);try(OutputStreamos=t.getResponseBody()){os.write(response);}});// Create a second URI path.server.createContext("/foo",(vart)->{byte[]response="Foo!".getBytes();t.sendResponseHeaders(200,response.length);try(OutputStreamos=t.getResponseBody()){os.write(response);}});server.start();}}

Compatibility with previous Java versions

For differences between Java 8 and the latest supported Java version, seeMigrate from Java 8 to the latest Java runtime.

Environment variables

The following environment variables are set by the runtime:

Environment variableDescription
GAE_APPLICATIONThe ID of your App Engine application.This ID is prefixed with 'region code~'such as 'e~' for applications deployed in Europe.
GAE_DEPLOYMENT_IDThe ID of the current deployment.
GAE_ENVThe App Engine environment. Set tostandard.
GAE_INSTANCEThe ID of the instance on which your service is currently running.
GAE_MEMORY_MBThe amount of memory available to the application process, in MB.
GAE_RUNTIMEThe runtime specified in yourapp.yaml file.
GAE_SERVICEThe service name specified in yourapp.yaml file. If no service name is specified, it is set todefault.
GAE_VERSIONThe current version label of your service.
GOOGLE_CLOUD_PROJECTThe Google Cloud project ID associated with your application.
PORTThe port that receives HTTP requests.
NODE_ENV (Only available in the Node.js runtime)Set toproduction when your service is deployed.

You candefine additional environment variables in yourapp.yaml file,but the above values cannot be overridden, except forNODE_ENV.

HTTPS and forwarding proxies

App Engine terminates HTTPS connections at the load balancer andforwards requests to your application. Some applications need to determinethe original request IP and protocol. The user's IP address is available inthe standardX-Forwarded-For header. Applications that require thisinformation should configure their web framework to trust the proxy.

Filesystem access

The runtime includes a writable/tmp directory, with all other directorieshaving read-only access. Writing to/tmp takes up system memory.

Metadata server

Each instance of your application can use the App Engine metadata serverto query information about the instance and your project.

Note: Custom metadata is not supported in the standard environment.

You can access the metadata server through the following endpoints:

  • http://metadata
  • http://metadata.google.internal

Requests sent to the metadata server must include the request headerMetadata-Flavor: Google. This header indicates that the request was sent withthe intention of retrieving metadata values.

The following table lists the endpoints where you can make HTTP requests forspecific metadata:

Metadata endpointDescription
/computeMetadata/v1/project/numeric-project-idThe project number assigned to your project.
/computeMetadata/v1/project/project-idThe project ID assigned to your project.
/computeMetadata/v1/instance/regionThe region the instance is running in.
/computeMetadata/v1/instance/service-accounts/default/aliases
/computeMetadata/v1/instance/service-accounts/default/emailThe default service account email assigned to your project.
/computeMetadata/v1/instance/service-accounts/default/Lists all the default service accounts for your project.
/computeMetadata/v1/instance/service-accounts/default/scopesLists all the supported scopes for the default service accounts.
/computeMetadata/v1/instance/service-accounts/default/tokenReturns the auth token that can be used to authenticate your application to other Google Cloud APIs.

For example, to retrieve your project ID, send a request tohttp://metadata.google.internal/computeMetadata/v1/project/project-id.

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 2025-12-15 UTC.