Google Cloud Platform

Configuring appengine-web.xml

Python |Java |PHP |Go

In addition to the web.xml deployment descriptor, an App Engine Java application uses a configuration file, named appengine-web.xml, to specify the app's registered application ID and the version identifier of the latest code, and to identify which files in the app's WAR are static files (like images) and which are resource files used by the application. The appcfg command uses this information when you upload the app.

Note: If you created your project using the Google Developers Console, your project has a title and an ID. In the instructions that follow, the project title and ID can be used wherever an application title and ID are mentioned. They are the same thing.

  1. About appengine-web.xml
  2. Static files and resource files
  3. System properties and environment variables
  4. Configuring Secure URLs (SSL)
  5. Enabling sessions
  6. Reserved URLs
  7. Inbound services
  8. Warmup requests
  9. Disabling precompilation
  10. Custom error responses
  11. Using concurrent requests
  12. Custom PageSpeed configuration (Deprecated)
  13. Auto ID policy
  14. URLFetch timeout

About appengine-web.xml

An App Engine Java app must have a file named appengine-web.xml in its WAR, in the directory WEB-INF/. This is an XML file whose root element is <appengine-web-app>. A minimal file that specifies the application ID, a version identifier, and no static files or resource files looks like this:

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="">

The <application> element contains the application's ID. This is the application ID you register when you create your application in the Google Developers Console. When you upload your app, appcfg gets the application ID from this file.

The <version> element contains the version identifier for the latest version of the app's code. The version identifier can contain lowercase letters, digits, and hyphens. It cannot begin with the prefix "ah-" and the names "default" and "latest" are reserved and cannot be used.

appcfg uses this version identifier when it uploads the application, telling App Engine to either create a new version of the app with the given identifier, or replace the version of the app with the given identifier if one already exists. You can test new versions of your app with a URL using "-dot-" as a subdomain separator in the URL, e.g., https://_version_id_-dot- Using the Google Developers Console, you can select the default version of your app. The default version is loaded when no version, or an invalid version, is specified.

The <threadsafe> element defines whether App Engine can send multiple requests at the same time to a given web server. It is further described in the section Using concurrent requests.

The <static-files> and <resource-files> elements are described in the next section.

You can find the DTD and schema specifications for this file in the SDK's docs/ directory.

Static files and resource files

Many web applications have files that are served directly to the user's browser, such as images, CSS style sheets, or browser JavaScript code. These are known as static files because they do not change, and can benefit from web servers dedicated just to static content. App Engine serves static files from dedicated servers and caches that are separate from the application servers.

Files that are accessible by the application code using the filesystem are called resource files. These files are stored on the application servers with the app.

By default, all files in the WAR are treated as both static files and resource files, except for JSP files, which are compiled into servlet classes and mapped to URL paths, and files in the WEB-INF/ directory, which are never served as static files and always available to the app as resource files.

You can adjust which files are considered static files and which are considered resource files using elements in the appengine-web.xml file. The <static-files> element specifies patterns that match file paths to include and exclude from the list of static files, overriding or amending the default behavior. Similarly, the <resource-files> element specifies which files are considered resource files.

Including and excluding files

Path patterns are specified using zero or more <include> and <exclude> elements. In a pattern, '*' represents zero or more of any character in a file or directory name, and ** represents zero or more directories in a path. Files and directories matching <exclude> patterns will not be uploaded when you deploy your app to App Engine. However, these files and directories will still be accessible to your application when running on the local Development Server.

An <include> element overrides the default behavior of including all files. An <exclude> element applies after all <include> patterns (as well as the default if no explicit <include> is provided).

The following example demonstrates how to designate all .png files as static files (except those in the data/ directory and all of its subdirectories):

  <include path="/**.png" />
  <exclude path="/data/**.png" />

Similarly, the following sample demonstrates how to designate all .xml files as resource files (except those in the feeds/ directory and all of its subdirectories):

  <include path="/**.xml" />
  <exclude path="/feeds/**.xml" />

You can also set HTTP headers to use when responding to requests to these resources.

  <include path="/my_static-files" >
    <http-header name="Access-Control-Allow-Origin" value="" />

Changing the MIME type for static files

By default, static files are served using a MIME type selected based on the filename extension. You can associate custom MIME types with filename extensions for static files in web.xml using <mime-mapping> elements.

Changing the root directory

The <public-root> is a directory in your application that contains the static files for your application. When a request for a static file is made, the <public-root> for your application is prepended to the request path. This gives the path of an application file containing the content that is being requested.

The default <public-root> is /.

For example, the following would map the URL path /index.html to the application file path /static/index.html:


Static cache expiration

Unless told otherwise, web proxies and browsers retain files they load from a website for a limited period of time.

You can configure a cache duration for specific static file handlers by providing an expiration attribute to <static-files><include ... >. The value is a string of numbers and units, separated by spaces, where units can be `d` for days, `h` for hours, `m` for minutes, and `s` for seconds. For example, "4d 5h" sets cache expiration to 4 days and 5 hours after the file is first requested. If the expiration time is omitted, the production server defaults to 10 minutes.

(Script handlers can set cache durations by returning the appropriate HTTP headers to the browser.)

For example:

  <include path="/**.png" expiration="4d 5h" />

System properties and environment variables

The appengine-web.xml file can define system properties and environment variables that are set when the application is running.

  <property name="myapp.maximum-message-length" value="140" />
  <property name="myapp.notify-every-n-signups" value="1000" />
  <property name="myapp.notify-url" value="" />

  <env-var name="DEFAULT_ENCODING" value="UTF-8" />

To avoid conflicts with your local environment, the development server does not set environment variables based on this file, and requires that the local environment have these variables already set to matching values. (This does not apply to system properties.)

dev_appserver war

When running on App Engine, the environment is created with these variables already set.

Configuring Secure URLs (SSL)

By default, any user can access any URL using either HTTP or HTTPS. You can configure an app to require HTTPS for certain URLs in the deployment descriptor. See Deployment Descriptor: Secure URLs.

If you want to disallow the use of HTTPS for the application, put the following in the appengine-web.xml file:


There is no way to disallow HTTPS for some URL paths and not others in the Java runtime environment.

Enabling sessions

App Engine includes an implementation of sessions, using the servlet session interface. The implementation stores session data in the App Engine datastore for persistence, and also uses memcache for speed. As with most other servlet containers, the session attributes that are set with session.setAttribute() during the request are persisted at the end of the request.

This feature is off by default. To turn it on, add the following to appengine-web.xml:


The implementation creates datastore entities of the kind _ah_SESSION, and memcache entries using keys with a prefix of _ahs.

It's possible to reduce request latency by configuring your application to asynchronously write HTTP session data to the datastore:

<async-session-persistence enabled="true" />

With async session persistence turned on, App Engine will submit a Task Queue task to write session data to the datastore before writing the data to memcache. By default the task will be submitted to the default queue. If you'd like to use a different queue, add the queue-name attribute:

<async-session-persistence enabled="true" queue-name="myqueue"/>

Reserved URLs

All URLs that begin with /_ah/ are reserved by App Engine for features or administrative purposes. Some URLs are routed to App Engine feature handlers, while others are called by App Engine for special purposes and are expected to be mapped to request handlers in your app (for example, /_ah/warmup for Warm-up Requests).

The URL /form is also reserved by App Engine. Requests for this URL are not routed to the app, and always return a 404 Not Found error.

Inbound services

Before an application can receive email or XMPP messages, the application must be configured to enable the service. You enable the service for a Java app by including an <inbound-services> section in the appengine-web.xml file. The following inbound services are available:

For example, you can enable mail and warmup by specifying the following in appengine-web.xml:


Disabling precompilation

App Engine uses a "precompilation" process with the Java bytecode of an app to enhance the performance of the app in the Java runtime environment. Precompiled code functions identically to the original bytecode.

If for some reason you prefer that your app not use precompilation, you can turn it off by adding the following to your appengine-web.xml file:


Warmup requests

App Engine frequently needs to load application code into a fresh instance. This happens when you redeploy the application, when the load pattern has increased beyond the capacity of the current instances, or simply due to maintenance or repairs of the underlying infrastructure or physical hardware.

Loading new application code on a fresh instance can result in loading requests. Loading requests can result in increased request latency for your users, but you can avoid this latency using warmup requests. Warmup requests load application code into a new instance before any live requests reach that instance.

App Engine attempts to detect when your application needs a new instance, and (assuming that warmup requests are enabled for your application) initiates a warmup request to initialize the new instance. However, these detection attempts do not work in every case. As a result, you may encounter loading requests, even if warmup requests are enabled in your app. For example, if your app is serving no traffic, the first request to the app will always be a loading request, not a warmup request.

Warmup requests use instance hours like any other request to your App Engine application. In most cases, you won't notice an increase in instance hours, since your application is simply initializing in a warmup request instead of a loading request. Your instance hour usage will likely increase if you decide to do more work (such as precaching) during a warmup request. If you set a minimum number of idle instances, you may encounter warmup requests when those instances first start, but they will remain available after that time.

The default warmup request causes all JAR files to be indexed in memory and initializes your application and filters. The following sections describe how to configure warmup requests and create warmup logic for your application:


Warmup requests are enabled by default for Java applications configured via appengine-web.xml.

With warmup requests enabled, the App Engine infrastructure issues GET requests to /_ah/warmup, initializing servlets, ServletContextListeners, and custom warmup servlets - which allow you to initialize your application's code as it requires. You may or may not need to implement your own handler for /_ah/warmup depending on which of these methods you choose.

To disable warmup requests, specify the optional <warmup-requests-enabled> element in appengine-web.xml with a value of false:


Using a <load-on-startup> servlet

The easiest way to provide warmup logic is to mark your own servlets as <load-on-startup> in web.xml. This method requires no changes to your application code, and initializes all specified servlets when your application initializes. The following example demonstrates how to load my-servlet on startup:


These lines load the specified servlet class and invoke the servlet's init() method. The warmup request initializes the specified servlets before servicing any live requests. However, if there is no warmup request, the servlets specified in <load-on-startup> are registered upon the first request to a new instance, which result in a loading request. As noted earlier, App Engine may not issue a warmup request every time your application needs a new instance.

Using a ServletContextListener

If you have custom logic that you want to run before any of your servlets is invoked, the standard Java mechanism to arrange for that code to be executed is to register a ServletContextListener in web.xml.


And then supply a class alongside your servlet and filter code:

public class MyListener implements ServletContextListener {
  public void contextInitialized(ServletContextEvent event) {
    // This will be invoked as part of a warmup request, or the first user
    // request if no warmup request was invoked.
  public void contextDestroyed(ServletContextEvent event) {
    // App Engine does not currently invoke this method.

The ServletContextListener runs during a warmup request. If there is no warmup request, it runs upon the first request to a new instance. This may result in loading requests.

Using a custom warmup servlet

As noted earlier, the prediction algorithm to initiate warmup requests for new instances does not work in every case. Even with this feature enabled, you may encounter loading requests. Executing expensive logic (such as precaching) during a loading request may incur additional load time when a new instance starts to run.

The custom warmup servlet invokes the servlet's service method only during a warmup request. By placing expensive logic in a custom warmup servlet, you can avoid increased load times on loading requests.

To create a custom warmup servlet, simply override the built-in servlet definition for _ah_warmup in web.xml:


Custom error responses

When certain errors occur, App Engine serves a generic error page. You can configure your app to serve a custom static file instead of these generic error pages, so long as the custom error data is less than 10 kilobytes. You can set up different static files to be served for each supported error code by specifying the files in your app's appengine-web.xml file. To serve custom error pages, add a <static-error-handlers> section to your appengine-web.xml, as in this example:

  <handler file="default_error.html" />
  <handler file="over_quota.html" error-code="over_quota" />

Each file entry indicates a static file that should be served in place of the generic error response. The error-code indicates which error code should cause the associated file to be served. Supported error codes are as follows:

The error-code is optional; if it's not specified, the given file is the default error response for your app.

You can optionally specify a mime-type to use when serving the custom error. See for a complete list of MIME types.

Using concurrent requests

When the threadsafe element in appengine-web.xml is false, App Engine sends requests serially to a given web server. When the value is true, App Engine can send multiple requests in parallel:


Custom PageSpeed configuration (Deprecated)

Deprecation Notice: The App Engine integration with the PageSpeed service is deprecated as of May 6, 2015 and will be turned off on December 1, 2015. For complete details, see the PageSpeed service turndown documentation.

In order to use PageSpeed you must enable Billing and enable PageSpeed using the Admin Console.

When enabled, PageSpeed Service will be applied globally to your application. All versions of your app will be automatically optimized with the same configuration, that of the most-recently updated version. If you want to try a new configuration, perhaps to test some "risky" optimizations, you might expect that you could do so in a test Application Version while your users continue to use the default Application Version. But since updating the test version's configuration applies to all versions, the "risky" settings are applied to the version that your users use, too. Instead, to try out these settings, you could

  • Turn off PageSpeed for your application, update PageSpeed configuration, and view your site using the PageSpeed chrome extension; or
  • Copy the relevant parts of your application to a separate test application that has its own application ID and versions.

PageSpeed is a family of tools for optimizing the performance of web pages. You can use the Application Console to enable PageSpeed with a solid set of safe default optimizations. You can also edit your application configuration to fine-tune PageSpeed. You can configure PageSpeed to ignore some URLs; you can turn on some "risky" optimizations that don't work for all sites but might work for yours. For a custom PageSpeed configuration, you can add a pagespeed section to your application configuration. An example that shows the possible parts (but not all choices) of pagespeed:


This section may have any or all of the following parts:

Which domains' content PageSpeed should rewrite. Normally, PageSpeed only rewrites data served by your application. But you can tell PageSpeed to rewrite content from other domains when your application shows that data. For example, your application might use a free image hosting service on some other domain. Since the image hosting site isn't part of your application, PageSpeed doesn't optimize those images by default. You might want it to optimize these images: they can be compressed and cached by Google, and thus displayed faster. You might not want it to optimize these images: Since pagespeed optimizes the images, you will be charged whenever those images are served.
This is a list of URLS; the '*' character is a wildcard. PageSpeed won't try to optimize URLs matching these URLs. This can be especially useful if you turn on some "risky" optimizations that break content for some URLs but make the rest of your site much much faster. By default, there is no blacklist.
enabled-rewriter, disabled-rewriter
By default, some "safe" optimization rewriters are turned on. Other "risky" optimizations are not turned on. You can choose more optimizations to use by listing them in enabled-rewriter; you can turn off default rewriters by listing them in disabled-rewriter. The following rewriters are available:

HTML Rewriters

CSS Rewriters

Image Rewriters

JavaScript Rewriters

Auto ID policy

If you are setting entity identifiers automatically, you can change the method employed by setting the auto ID policy. You can choose default (default is also applied if you specify nothing) or legacy. Please note however that the legacy option will be deprecated in a future release and will eventually be removed. For more information, see our blog post where we announced the change.


URLFetch timeout

You can set a deadline for each URLFetch request. By default, the deadline for a fetch is 5 seconds. You can change this default by including the following setting in your appengine-web.xml configuration file. Specify the timeout in seconds:

    <property name="appengine.api.urlfetch.defaultDeadline" value="10"/>