If you are creating a new function, see the Console Quickstart on Cloud Run. The content on this page only applies to existing legacy functions created with the Cloud Functions v1 API.
Stay organized with collections
Save and categorize content based on your preferences.
The Java Runtime
Overview
Your Cloud Run function runs in an environment consisting of an operating
system version plus add-on packages, language support, and
the Functions Framework library that supports and invokes your function.
This environment is identified by the language version, and is known as the
runtime.
Cloud Run functions supports several versions of Java, listed on the
Runtime support page. You can
select the preferred Ruby Java for your function during deployment.
gcloud
If you're using the Google Cloud CLI, specify the runtime
by using the --runtime parameter. The --entry-point flag specifies the
fully qualified class name (FQN). For example:
If you're using the Google Cloud console, select the runtime when
you create and deploy your function. See the
Google Cloud console quickstart for
detailed instructions.
Function preparation
You can prepare a function directly from the Google Cloud console or write it on
your local machine and upload it. To prepare your local machine for Java
development, see Setting Up a Java Development Environment.
The library that invokes your function is the Java Functions
Framework.
To get started with Java on Cloud Run functions, see the
Quickstart.
Source code structure
For Cloud Run functions to find your function's definition, your
source code must follow a specific structure. See
Writing Cloud Run functions
for more information.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["\u003cp\u003eCloud Run functions utilize a specific runtime environment, which includes the operating system, add-on packages, language support, and the Functions Framework library that is identified by the language version.\u003c/p\u003e\n"],["\u003cp\u003eYou can select a preferred Java runtime version for your Cloud Run function during deployment, with supported versions listed on the Runtime support page.\u003c/p\u003e\n"],["\u003cp\u003eWhen deploying via the Google Cloud CLI, you use the \u003ccode\u003e--runtime\u003c/code\u003e parameter to specify the Java runtime and the \u003ccode\u003e--entry-point\u003c/code\u003e flag for the fully qualified class name.\u003c/p\u003e\n"],["\u003cp\u003eYou can prepare a Java function either directly through the Google Cloud console or locally, and specify dependencies using Maven or Gradle.\u003c/p\u003e\n"],["\u003cp\u003eCertain environment variables are automatically set by the Java runtime for use within your Cloud Run function.\u003c/p\u003e\n"]]],[],null,["# The Java Runtime\n================\n\nOverview\n--------\n\nYour Cloud Run function runs in an environment consisting of an operating\nsystem version plus add-on packages, language support, and\nthe Functions Framework library that supports and invokes your function.\nThis environment is identified by the language version, and is known as the\nruntime.\n\nFor information about runtimes in general, and to learn which Ubuntu version\neach Java runtime uses, see the [Cloud Run functions execution\nenvironment](/functions/1stgendocs/concepts/execution-environment#java).\n\nSelect your runtime\n-------------------\n\nCloud Run functions supports several versions of Java, listed on the\n[Runtime support](/functions/1stgendocs/runtime-support#java) page. You can\nselect the preferred Ruby Java for your function during deployment. \n\n### gcloud\n\nIf you're using the Google Cloud CLI, specify the runtime\nby using the `--runtime` parameter. The `--entry-point` flag specifies the\nfully qualified class name (FQN). For example: \n\n```bash\ngcloud functions deploy NAME --no-gen2 --entry-point FQN --no-gen2 --runtime java17 --trigger-http\n```\n\nFor more deployment parameters, see [Deploy a Cloud Run function](/functions/1stgendocs/deploy#basics).\n\n### Console\n\nIf you're using the Google Cloud console, select the runtime when\nyou create and deploy your function. See the\n[Google Cloud console quickstart](/functions/1stgendocs/console-quickstart-1st-gen) for\ndetailed instructions.\n\nFunction preparation\n--------------------\n\nYou can prepare a function directly from the Google Cloud console or write it on\nyour local machine and upload it. To prepare your local machine for Java\ndevelopment, see [Setting Up a Java Development Environment](/java/docs/setup).\nThe library that invokes your function is the [Java Functions\nFramework](/functions/1stgendocs/functions-framework).\n\nTo get started with Java on Cloud Run functions, see the\n[Quickstart](/functions/1stgendocs/create-deploy-gcloud-1st-gen).\n\nSource code structure\n---------------------\n\nFor Cloud Run functions to find your function's definition, your\nsource code must follow a specific structure. See\n[Writing Cloud Run functions](/functions/1stgendocs/writing#structuring_source_code)\nfor more information.\n\nSpecifying dependencies\n-----------------------\n\nYou can specify dependencies for your function using [Maven](https://maven.apache.org/) or [Gradle](https://gradle.org/). For more information,\nsee [Specifying dependencies in\nJava](/functions/1stgendocs/writing/specifying-dependencies-java).\n\nEnvironment variables\n---------------------\n\nYour Java runtime automatically sets certain environment variables for your\nfunction to use as needed. For details, see [Using Environment\nVariables](/functions/1stgendocs/configuring/env-var).\n\nWhat's next\n-----------\n\n- [Learn how to use Java frameworks](/functions/1stgendocs/concepts/java-frameworks) that provide out-of-the-box support for writing Java Cloud Run functions.\n- [Learn how to use popular APIs and logging\n frameworks](/functions/1stgendocs/concepts/java-logging) to configure the logging behavior of Java Cloud Run functions.\n- [Learn about the other JVM languages](/functions/1stgendocs/concepts/jvm-langs) you can use to write Cloud Run functions: Kotlin, Groovy, and Scala."]]