Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Ambiente de execução Java
Informações gerais
A função do Cloud Run é executada em um ambiente que consiste em uma versão do sistema
operacional, além de pacotes complementares, suporte a linguagens e a biblioteca
do Functions Framework que dá suporte e invoca a função.
Esse ambiente é identificado pela versão da linguagem e conhecido como ambiente de execução.
Para mais informações sobre tempos de execução em geral e para saber qual versão
do Ubuntu cada ambiente de execução Java usa, consulte o ambiente
de execução do Cloud Run functions.
Selecionar o ambiente de execução
O Cloud Run functions aceita várias versões Java, que estão listadas na
página Suporte ao ambiente de execução. É possível
selecionar seu Ruby Java preferencial para a função durante a implantação.
gcloud
Se você estiver usando a Google Cloud CLI, especifique o ambiente de execução usando o parâmetro --runtime. A sinalização --entry-point especifica o nome de classe totalmente qualificado (FQN, na sigla em inglês). Exemplo:
Se você estiver usando o console do Google Cloud, selecione o ambiente de execução ao criar e implantar a função. Consulte o guia de início rápido do console do Google Cloud para instruções detalhadas.
Para começar a usar o Java no Cloud Run functions, consulte o
Guia de início rápido.
Estrutura do código-fonte
Para que as funções do Cloud Run encontrem a definição da sua função, seu código-fonte precisa seguir uma estrutura específica. Consulte
Como escrever funções do Cloud Run
para mais informações.
O ambiente de execução do Java define automaticamente certas variáveis de ambiente para que sua função use conforme necessário. Para detalhes, consulte
Como usar variáveis de ambiente.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 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."]]