Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Java Runtime
Descripción general
Tu función de Cloud Run Functions se ejecuta en un entorno que consta de una versión del sistema operativo, además de paquetes de complementos, compatibilidad con lenguajes y la biblioteca de Functions Framework que admite e invoca la función.
Este entorno se identifica mediante la versión del lenguaje y se conoce como el entorno de ejecución.
Para obtener información sobre los entornos de ejecución en general y saber qué versión de Ubuntu usa cada entorno de ejecución de Java, consulta el entorno de ejecución de Cloud Run Functions.
Selecciona tu entorno de ejecución
Cloud FuCloud Run Functionsnctions admite varias versiones de Java, que se enumeran en la página Compatibilidad con el entorno de ejecución. Puedes
seleccionar Java para Ruby que prefieras para tu función durante la implementación.
gcloud
Si usas Google Cloud CLI, especifica el entorno de ejecución mediante el parámetro --runtime. La marca --entry-point especifica el nombre de clase completamente calificado (FQN). Por ejemplo:
Si usas la consola de Google Cloud, selecciona el entorno de ejecución cuando creas y cuando implementas tu función. Consulta la guía de inicio rápido de la consola de Google Cloud para obtener instrucciones detalladas.
Preparación de funciones
Puedes preparar una función directamente desde la consola de Google Cloud o escribirla en tu máquina local y subirla. Si deseas preparar tu máquina local para el desarrollo en Java, consulta Configura un entorno de desarrollo de Java.
La biblioteca que invoca tu función es el Functions Framework para Java.
Para comenzar a usar Java en Cloud Run Functions, consulta la guía de inicio rápido.
Estructura del código fuente
Para que Cloud Run Functions encuentre la definición de tu función, tu código fuente debe seguir una estructura específica. Consulta Escribe funciones de Cloud Run para obtener más información.
El entorno de ejecución de Java configura automáticamente ciertas variables de entorno para que tu función las use según sea necesario. Para obtener más detalles, consulta Usa variables de entorno.
¿Qué sigue?
Aprende a usar los frameworks de Java, que brindan compatibilidad lista para usar con la escritura de funciones de Cloud Run Functions basadas en Java.
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-04-23 (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."]]