Java 8 已停止支援,並將於 2026 年 1 月 31 日
淘汰。淘汰後,您將無法部署 Java 8 應用程式,即使貴機構先前使用機構政策重新啟用舊版執行階段的部署作業也一樣。現有的 Java 8 應用程式在
淘汰日期後,仍會繼續執行並接收流量。建議您
改用最新支援的 Java 版本。
設定檔
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
服務的每個版本是由 .yaml
檔案來定義,該檔案會說明服務與版本的名稱。YAML 檔案通常與其定義的服務同名,但這並非必要條件。如要部署某項服務的數個版本,可以在同一個目錄中建立多個 yaml 檔案 (每個版本各一個)。
一般來說,您可以為各項服務建立目錄,當中包含該項服務的 YAML 檔案和相關聯原始碼。最上層應用程式目錄中會包含選用的應用程式層級設定檔 (dispatch.yaml
、cron.yaml
、index.yaml
和 queue.yaml
)。以下範例呈現了三項服務。service1
和 service2
中的原始檔與 YAML 檔案位於相同層級,service3
中則包含兩個版本的 YAML 檔案。

如為小型、簡易型專案,您可以將所有應用程式檔案存放於同一個目錄:

每一個 YAML 檔案都必須含有一個版本參數。如要定義預設服務,您可以明確納入 service: default
參數,或是將服務參數排除在檔案之外。
每個服務設定檔都會定義特定服務/版本的資源調度類型和執行個體類別。視指定的資源調度類型而定,您必須使用不同的資源調度參數。如果您未指定資源調度設定,預設值為自動調整資源配置。如需資源調度和執行個體類別設定的相關說明,請參閱 appengine-web.xml
參考資料部分。
您也可以針對各項服務指定設定,將網址要求對應至特定指令碼及識別靜態檔案,藉此提升伺服器的工作效率。這些設定也會包含在 yaml 檔案中,相關說明請見 appengine-web.xml
參考資料部分。
預設服務
每個應用程式均有一項預設服務。您可以在 appengine-web.xml
中使用 service: default
設定來定義預設服務,不過此為選用動作。凡是與服務有關的設定參數均可套用至預設服務。
選用設定檔
這些設定檔控制適用於應用程式中所有服務的選用功能:
如要在 App Engine 中部署這些設定檔的更新內容,請在設定檔所在的目錄中執行以下指令:
gcloud app deploy [CONFIG_FILE]
範例
以下範例顯示了如何為具備兩項服務的應用程式設定 WAR 目錄結構中的各個檔案。這兩項服務分別為處理網路要求的預設服務,以及負責處理後端的「my-service
」服務。
假設頂層的 EAR 目錄是「my-application」,則您必須定義 my-application/META-INF/appengine-application.xml
檔案:
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<appengine-application xmlns="http://appengine.google.com/ns/1.0">
<application>my-application</application>
</appengine-application>
為 my-application/default
和 my-application/my-service
這兩項服務建立 WAR 目錄。
接著,請在每個 WAR 目錄中各建立一個 appengine-web.xml
檔案,以便指定服務的參數。該檔案中必須包含服務的版本名稱。如要定義預設服務,您可以明確納入 <service>default</service>
參數,也可以將其排除在檔案之外。以下是定義預設服務的 my-application/default/WEB-INF/appengine-web.xml
檔案:
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>my-application</application>
<module>default</module>
<version>uno</version>
<threadsafe>true</threadsafe>
</appengine-web-app>
這個檔案 my-application/my-service/WEB-INF/appengine-web.xml
定義了處理背景要求的服務:
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>my-application</application>
<module>my-service</module>
<version>uno</version>
<threadsafe>true</threadsafe>
<manual-scaling>
<instances>5</instances>
</manual-scaling>
</appengine-web-app>
最後,請定義列舉服務的 my-application/META-INF/application.xml
檔案。請注意,預設服務應為清單中的第一項服務。
<?xml version="1.0"
encoding="UTF-8"?>
<application
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/application_5.xsd"
version="5">
<description>GAE Java SuperFun app</description>
<display-name>SuperFun</display-name>
<!-- Services -->
<!-- The default service should be listed first -->
<module>
<web>
<web-uri>default</web-uri>
<context-root>default</context-root>
</web>
</module>
<module>
<web>
<web-uri>my-service</web-uri>
<context-root>my-service</context-root>
</web>
</module>
</application>
App Engine 會忽略 <context-root>
元素,因此 HTTP 用戶端在呼叫服務時,無須將其附加至網址路徑的最前方。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-09-04 (世界標準時間)。
[[["容易理解","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\u003eService versions are defined in \u003ccode\u003e.yaml\u003c/code\u003e files, which specify the service name and version, and multiple versions of a service can be defined by creating multiple YAML files in the same directory.\u003c/p\u003e\n"],["\u003cp\u003eEach service's configuration file defines its scaling type and instance class, with automatic scaling as the default if not specified, and these configurations are found in the \u003ccode\u003eappengine-web.xml\u003c/code\u003e reference section.\u003c/p\u003e\n"],["\u003cp\u003eEvery application has a single default service, which can be designated explicitly with \u003ccode\u003eservice: default\u003c/code\u003e or by omitting the service parameter in the \u003ccode\u003eappengine-web.xml\u003c/code\u003e file.\u003c/p\u003e\n"],["\u003cp\u003eOptional configuration files, such as \u003ccode\u003edispatch.yaml\u003c/code\u003e, \u003ccode\u003equeue.yaml\u003c/code\u003e, \u003ccode\u003eindex.yaml\u003c/code\u003e, and \u003ccode\u003ecron.yaml\u003c/code\u003e, are used to manage routing, queues, indexes, and scheduled tasks, and are deployed using the \u003ccode\u003egcloud app deploy [CONFIG_FILE]\u003c/code\u003e command.\u003c/p\u003e\n"],["\u003cp\u003eIn an example of an application with two services, the default service and \u003ccode\u003emy-service\u003c/code\u003e, each WAR directory contains an \u003ccode\u003eappengine-web.xml\u003c/code\u003e file that defines the specific parameters for the service and the \u003ccode\u003eapplication.xml\u003c/code\u003e file enumerates the services, with the default service listed first.\u003c/p\u003e\n"]]],[],null,["# Configuration Files\n\nEach version of a service is defined in a `.yaml` file, which gives the name of\nthe service and version. The YAML file usually takes the same name as the\nservice it defines, but this is not required. If you are deploying several\nversions of a service, you can create multiple yaml files in the same directory,\none for each version.\n\nTypically, you create a directory for each service, which contains the service's\nYAML files and associated source code. Optional application-level configuration\nfiles (`dispatch.yaml`, `cron.yaml`, `index.yaml`, and `queue.yaml`) are\nincluded in the top level app directory. The example below shows three services.\nIn `service1` and `service2`, the source files are at the same level as the YAML\nfile. In `service3`, there are YAML files for two versions.\n\nFor small, simple projects, all the app's files can live in one directory:\n\nEvery YAML file must include a version parameter. To define the default service,\nyou can explicitly include the parameter `service: default` or leave the service\nparameter out of the file.\n\nEach service's configuration file defines the scaling type and instance class\nfor a specific service/version. Different scaling parameters are used depending\non which type of scaling you specify. If you do not specify scaling, automatic\nscaling is the default. The scaling and instance class settings are described in\nthe [`appengine-web.xml`\nreference](/appengine/docs/legacy/standard/java/config/appref#scaling_elements)\nsection.\n\nFor each service you can also specify settings that map URL requests to specific\nscripts and identify static files for better server efficiency. These settings\nare also included in the yaml file and are described in the\n[`appengine-web.xml` reference](/appengine/docs/legacy/standard/java/config/appref)\nsection.\n\n### The default service\n\nEvery application has a single default service. You can define the default\nservice in the `appengine-web.xml` with the setting\n`service: default`, but it isn't necessary to do this. All configuration\nparameters relevant to services can apply to the default service.\n\n### Optional configuration files\n\nThese configuration files control optional features that apply to all the\nservices in an app:\n\n- [`dispatch.yaml`](/appengine/docs/legacy/standard/java/reference/dispatch-yaml) overrides routing default rules by sending incoming requests to a specific service based on the path or hostname in the URL.\n- [`queue.yaml`](/appengine/docs/legacy/standard/java/config/queueref) configures both push queues and pull queues.\n- [`index.yaml`](/appengine/docs/legacy/standard/java/configuring-datastore-indexes-with-index-yaml) specifies which indexes your app needs if using Datastore queries.\n- [`cron.yaml`](/appengine/docs/legacy/standard/java/config/cronref) configures regularly scheduled tasks that operate at defined times or regular intervals.\n\nTo deploy updates of these configuration files to App Engine, run the\nfollowing command from the directory where they are located: \n\n gcloud app deploy [CONFIG_FILE]\n\n### An example\n\nHere is an example of how you would configure the various files in a WAR\ndirectory structure for an application that has two services: a default service\nthat handles web requests, plus another service (named `my-service`) for backend\nprocessing.\n\nAssuming that the top-level EAR directory is \"my-application,\" define the file\n`my-application/META-INF/appengine-application.xml`: \n\n \u003c?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?\u003e\n \u003cappengine-application xmlns=\"http://appengine.google.com/ns/1.0\"\u003e\n \u003capplication\u003emy-application\u003c/application\u003e\n \u003c/appengine-application\u003e\n\nCreate WAR directories for the two services: `my-application/default` and `my-application/my-service`.\n\nNow create an `appengine-web.xml` file in each WAR that specifies the parameters\nfor the service. The file must include a version name for the service. To define\nthe default service, you can explicitly include the `\u003cservice\u003edefault\u003c/service\u003e`\nparameter or leave it out of the file. Here is the file\n`my-application/default/WEB-INF/appengine-web.xml` that defines the default\nservice: \n\n \u003c?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?\u003e\n \u003cappengine-web-app xmlns=\"http://appengine.google.com/ns/1.0\"\u003e\n \u003capplication\u003emy-application\u003c/application\u003e\n \u003cmodule\u003edefault\u003c/module\u003e\n \u003cversion\u003euno\u003c/version\u003e\n \u003cthreadsafe\u003etrue\u003c/threadsafe\u003e\n \u003c/appengine-web-app\u003e\n\nThe file `my-application/my-service/WEB-INF/appengine-web.xml` defines the service that will handle background requests: \n\n \u003c?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?\u003e\n \u003cappengine-web-app xmlns=\"http://appengine.google.com/ns/1.0\"\u003e\n \u003capplication\u003emy-application\u003c/application\u003e\n \u003cmodule\u003emy-service\u003c/module\u003e\n \u003cversion\u003euno\u003c/version\u003e\n \u003cthreadsafe\u003etrue\u003c/threadsafe\u003e\n \u003cmanual-scaling\u003e\n \u003cinstances\u003e5\u003c/instances\u003e\n \u003c/manual-scaling\u003e\n \u003c/appengine-web-app\u003e\n\nFinally, define the file `my-application/META-INF/application.xml` that\nenumerates the services. Note that the default service should be the first\nservice listed. \n\n \u003c?xml version=\"1.0\"\n encoding=\"UTF-8\"?\u003e\n\n \u003capplication\n xmlns=\"http://java.sun.com/xml/ns/javaee\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xsi:schemaLocation=\"http://java.sun.com/xml/ns/javaee\n http://java.sun.com/xml/ns/javaee/application_5.xsd\"\n version=\"5\"\u003e\n\n \u003cdescription\u003eGAE Java SuperFun app\u003c/description\u003e\n \u003cdisplay-name\u003eSuperFun\u003c/display-name\u003e\n\n \u003c!-- Services --\u003e\n \u003c!-- The default service should be listed first --\u003e\n \u003cmodule\u003e\n \u003cweb\u003e\n \u003cweb-uri\u003edefault\u003c/web-uri\u003e\n \u003ccontext-root\u003edefault\u003c/context-root\u003e\n \u003c/web\u003e\n \u003c/module\u003e\n \u003cmodule\u003e\n \u003cweb\u003e\n \u003cweb-uri\u003emy-service\u003c/web-uri\u003e\n \u003ccontext-root\u003emy-service\u003c/context-root\u003e\n \u003c/web\u003e\n \u003c/module\u003e\n\n \u003c/application\u003e\n\nApp Engine will ignore the `\u003ccontext-root\u003e` elements, so HTTP clients need not\nprepend it to the URL path when addressing a service."]]