Jika Anda membuat fungsi baru, lihat Panduan Memulai Konsol di Cloud Run. Konten di halaman ini hanya berlaku untuk fungsi lama yang sudah ada yang dibuat dengan Cloud Functions v1 API.
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Runtime Java
Ringkasan
Fungsi Cloud Run Anda berjalan di lingkungan yang terdiri dari versi sistem operasi plus paket add-on, dukungan bahasa, dan library Functions Framework yang mendukung dan memanggil fungsi Anda.
Lingkungan ini diidentifikasi berdasarkan versi bahasa, dan dikenal sebagai runtime.
Untuk informasi tentang runtime secara umum, dan untuk mempelajari versi Ubuntu yang digunakan setiap runtime Java, lihat lingkungan eksekusi fungsi Cloud Run.
Memilih runtime Anda
Fungsi Cloud Run mendukung beberapa versi Java, yang tercantum di halaman Dukungan runtime. Anda dapat memilih Java Ruby yang diinginkan untuk fungsi Anda selama deployment.
gcloud
Jika Anda menggunakan Google Cloud CLI, tentukan runtime
menggunakan parameter --runtime. Flag --entry-point menentukan
nama class yang sepenuhnya memenuhi syarat (fully qualified class name/FQN). Contoh:
Jika Anda menggunakan konsol Google Cloud , pilih runtime saat membuat dan men-deploy fungsi. Lihat
panduan memulai konsolGoogle Cloud untuk
mengetahui petunjuk mendetail.
Persiapan fungsi
Anda dapat menyiapkan fungsi langsung dari konsol Google Cloud atau menulisnya di komputer lokal, lalu menguploadnya. Guna menyiapkan mesin lokal untuk pengembangan Java, lihat Menyiapkan Lingkungan Pengembangan Java.
Library yang memanggil fungsi Anda adalah Framework Fungsi
Java.
Untuk mulai menggunakan Java di fungsi Cloud Run, lihat Panduan memulai.
Struktur kode sumber
Agar fungsi Cloud Run dapat menemukan definisi fungsi Anda, kode sumber harus mengikuti struktur tertentu. Lihat artikel Menulis fungsi Cloud Run untuk mengetahui informasi selengkapnya.
Runtime Java Anda akan otomatis menetapkan variabel lingkungan tertentu untuk digunakan fungsi Anda sesuai kebutuhan. Untuk mengetahui detailnya, lihat Menggunakan Variabel Lingkungan.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-09-03 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."]]