[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[[["\u003cp\u003eThis guide outlines the process of installing and utilizing bundled services with the latest supported Java version for the App Engine standard environment, accessible through the App Engine API JAR.\u003c/p\u003e\n"],["\u003cp\u003eTo use legacy bundled services, your app must run a supported Java version and be configured using an \u003ccode\u003eappengine-web.xml\u003c/code\u003e file instead of \u003ccode\u003eapp.yaml\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eappengine-web.xml\u003c/code\u003e file requires specific settings based on the Java version (v21 and later on EE10, v21 on EE8, v17 and earlier) and the inclusion of \u003ccode\u003e<app-engine-apis>true</app-engine-apis>\u003c/code\u003e in \u003ccode\u003eweb.xml\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eJava 21 applications utilize a default entrypoint generated by App Engine buildpacks, which can be further customized using user-defined environment variables in the \u003ccode\u003eappengine-web.xml\u003c/code\u003e file, such as \u003ccode\u003eJAVA_OPTS\u003c/code\u003e, \u003ccode\u003eJAVA_HEAP_OPTS\u003c/code\u003e, and \u003ccode\u003eCPROF_ENABLE\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eMigrating to a second-generation Java runtime requires awareness of considerations such as JVM being part of instance memory, thread safety assumptions, and potential \u003ccode\u003eApiProxy$FeatureNotEnabledException\u003c/code\u003e errors if using unsupported APIs.\u003c/p\u003e\n"]]],[],null,["# Access legacy bundled services for Java 11+\n\nThis page describes how to install and use the bundled\nservices with the latest supported\n[Java version](/appengine/docs/standard/lifecycle/support-schedule#java) for\nthe App Engine standard environment. Your app can access the bundled services through the\n**App Engine API JAR**.\n\nBefore you begin\n----------------\n\n- Refer to the [list of legacy bundled services APIs](/appengine/docs/standard/services/overview)\n you can call in the latest supported Java version.\n\n- This page requires that your app is running a [supported](/appengine/docs/standard/java-gen2/services/(/appengine/docs/standard/lifecycle/support-schedule#java)) Java version. To migrate\n your app from the first-generation to the second-generation runtime, see\n [Migrate from Java 8 to the latest Java runtime](/appengine/migration-center/standard/migrate-to-second-gen/java-differences) and the [migration considerations](#migration) section.\n\n- If you use legacy bundled services and want to upgrade to Java 21,\n see [Upgrade an existing application](/appengine/docs/standard/java-gen2/upgrade-java-runtime)\n to learn more about your configuration options.\n\nInstall the App Engine API JAR\n------------------------------\n\nTo use legacy bundled services in your latest supported Java app, you must\nuse an [`appengine-web.xml`](/appengine/docs/standard/java-gen2/config/appref-xml)\nfile to configure your app (instead of an `app.yaml` file).\n\nThe following example demonstrates how to add configuration settings in your\n`appengine-web.xml` for version 21 and later on EE10 (default), version\n21 on EE8, and version 17 and earlier. To use the latest supported version on\nthe default configuration, you must update your application servlets and\ndependencies to include the `Jakarta` namespace. To learn more about your configuration options,\nsee [Upgrade an existing application](/appengine/docs/standard/java-gen2/upgrade-java-runtime).\n\nAdd the following settings in your `appengine-web.xml` file depending on the Java version: \n\n### v21 and later (EE10)\n\n \u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n \u003cappengine-web-app xmlns=\"http://appengine.google.com/ns/1.0\"\u003e\n \u003cruntime\u003ejava21\u003c/runtime\u003e \u003c!-- or another supported version --\u003e\n \u003capp-engine-apis\u003etrue\u003c/app-engine-apis\u003e\n \u003c/appengine-web-app\u003e\n\n### v21 (EE8)\n\n \u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n \u003cappengine-web-app xmlns=\"http://appengine.google.com/ns/1.0\"\u003e\n \u003cruntime\u003ejava21\u003c/runtime\u003e\n \u003csystem-properties\u003e \u003c!-- run your apps on EE8 --\u003e\n \u003cproperty name=\"appengine.use.EE8\" value=\"true\"/\u003e\n \u003c/system-properties\u003e\n \u003capp-engine-apis\u003etrue\u003c/app-engine-apis\u003e\n \u003c/appengine-web-app\u003e\n\n### v17 and earlier\n\n \u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n \u003cappengine-web-app xmlns=\"http://appengine.google.com/ns/1.0\"\u003e\n \u003cruntime\u003ejava17\u003c/runtime\u003e \u003c!-- or another supported version --\u003e\n \u003capp-engine-apis\u003etrue\u003c/app-engine-apis\u003e\n \u003c/appengine-web-app\u003e\n\nTo specify the legacy bundled services as a dependency, add the following\nlines in your `pom.xml` file: \n\n \u003cdependency\u003e\n \u003cgroupId\u003ecom.google.appengine\u003c/groupId\u003e\n \u003cartifactId\u003eappengine-api-1.0-sdk\u003c/artifactId\u003e\n \u003cversion\u003e2.0.31\u003c/version\u003e \u003c!-- or later--\u003e\n \u003c/dependency\u003e\n\nIf your app uses a `web.xml` file, you must add the `\u003capp-engine-apis\u003e` element\nand set it to `true`: \n\n \u003capp-engine-apis\u003etrue\u003c/app-engine-apis\u003e\n\nTo deploy your Java 21 app, run the\n[`mvn appengine:deploy`](/appengine/docs/standard/java-gen2/maven-reference)\ncommand, or the\n[`gcloud app deploy ~/my_app/WEB-INF/appengine-web.xml`](/sdk/gcloud/reference/app/deploy)\ncommand on a compiled and staged web application.\n\nDefault entrypoint used by Java 21\n----------------------------------\n\nJava 21 apps can benefit from extra user\nconfiguration when starting the JVM for web apps.\n\nThe default entrypoint used to boot the JVM is generated by App Engine buildpacks.\nEssentially, it is equivalent to define this entrypoint in the `appengine-web.xml` file. For example: \n\n```\njava --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.nio.charset=ALL-UNNAMED -showversion -Xms32M -Xmx204M -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:+PrintCommandLineFlags -Dclasspath.runtimebase=/base/java_runtime -Djava.class.path=/base/java_runtime/runtime-main.jar -Djava.library.path=/base/java_runtime: com/google/apphosting/runtime/JavaRuntimeMainWithDefaults --fixed_application_path=/workspace /base/java_runtime\n```\n\nWe don't recommend changing this default entrypoint as the memory settings are calculated based on the instance type (F1, F2, F4) and memory available.\n\nBy default, we use `--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.nio.charset=ALL-UNNAMED` to open some necessary JDK APIs.\n\nEntry Point Features\n--------------------\n\nThe entry point for the [second-generation](/appengine/docs/standard/runtimes)\nJava versions can be customized with user-defined environment\nvariables added in the `appengine-web.xml` configuration file.\n\nThe following table indicates the environment variables that can be used to enable/disable/configure features, and the default values if they are not set:\n\nIf not explicitly set, `JAVA_OPTS` is defaulted to: \n\n JAVA_OPTS:=-showversion \\\n $\u003cvar translate=\"no\"\u003eJAVA_HEAP_OPTS\u003c/var\u003e \\\n $\u003cvar translate=\"no\"\u003eJAVA_GC_OPTS\u003c/var\u003e \\\n $\u003cvar translate=\"no\"\u003eJAVA_USER_OPTS\u003c/var\u003e\n\nWhen `CPROF_ENABLE` is true, the default entrypoint adds the \u003cvar translate=\"no\"\u003e\u003ccode translate=\"no\" dir=\"ltr\"\u003ePROFILER_AGENT\u003c/code\u003e\u003c/var\u003e as:\n\n`-agentpath:/opt/cprof/profiler_java_agent.so=--logtostderr`\n\nFor example, if your application code needs more `-add-opens` flags, you can use the \u003cvar translate=\"no\"\u003e\u003ccode translate=\"no\" dir=\"ltr\"\u003eJAVA_USER_OPTS\u003c/code\u003e \u003c/var\u003e environment variable defined in the `appengine-web.xml` file: \n\n \u003cenv-variables\u003e\n \u003cenv-var name=\"JAVA_USER_OPTS\" value=\"--add-opens java.base/java.util=ALL-UNNAMED\" /\u003e\n \u003c/env-variables\u003e\n\nMigration considerations\n------------------------\n\nYou should be aware of the following considerations if you are migrating to\na second-generation Java runtime and your app uses legacy bundled services:\n\n- To test the legacy bundled services capabilities in your second-generation Java app, you can use the [local development server](/appengine/docs/standard/tools/using-local-server).\n- Unlike the Java 8 runtime, the second-generation Java runtimes include JVM as part of the instance memory. If you see memory-related errors in the logs, consider increasing the instance class size in your [`appengine-web.xml`](/appengine/docs/standard/java-gen2/config/appref-xml#syntax) file.\n- If your application is trying to call an API which is not enabled for the second-generation Java runtimes, it will receive a `com.google.apphosting.api.ApiProxy$FeatureNotEnabledException` error.\n- All apps are assumed to be thread safe in the second-generation Java runtimes. You must remove the `threadsafe` element in your `app.yaml` or `appengine-web.xml` file when [Migrate from Java 8 to the latest Java runtime](/appengine/migration-center/standard/migrate-to-second-gen/java-differences#key-differences).\n\nExample (Datastore)\n-------------------\n\nFor an example of how to use Firestore in Datastore mode (Datastore), see the\nlegacy bundled services for Java 11\n[code sample in GitHub](https://github.com/GoogleCloudPlatform/java-docs-samples/tree/main/appengine-java11-bundled-services/datastore)."]]