Deploying a Java App

Deploy your app to upload and run them on App Engine. When you deploy your apps, you create versions of those apps and their corresponding services in App Engine. You can deploy entire apps, including all the source code and configuration files, or you can deploy and update individual versions or configuration files.

To programmatically deploy your apps, use the Admin API.

Before you begin

Before you can deploy your app, you must have a Cloud Platform project and an App Engine application, see Managing Projects, Applications, and Billing for more information.

To deploy your app using Maven, you must:

Installing the appcfg tool (alternative)

To deploy your app with the appcfg tool, you must download and install the App Engine SDK for Java:

Download the SDK

Deploying an app

To deploy your app to App Engine, you run Maven (recommended) or the appcfg command from within the root directory of your application.

To deploy your app with Maven, run the following command from your project's top level directory, where the pom.xml file is located, for example:

mvn appengine:update

You will be prompted for an authorization code in the terminal window and your web browser will launch with a consent screen which you must accept in order to be authorized. Follow the prompts to copy any codes from the browser to the command line.

Using appcfg (alternative)

To deploy your app, run the appcfg command with the update action and the directory path of your WAR file, for example:

Windows

appengine-java-sdk\bin\appcfg.cmd [options] update [WAR_LOCATION]

Mac / Linux

./appengine-java-sdk/bin/appcfg.sh [options] update [WAR_LOCATION]

If you are using an HTTP proxy, include the --proxy argument to tell appcfg its address. If you use a different proxy for HTTPS, then also include the --proxy_https argument. See the appcfg command line arguments for more information.

Windows

appengine-java-sdk\bin\appcfg.cmd --proxy=10.1.2.3 update [WAR_LOCATION]

Mac / Linux

./appengine-java-sdk/bin/appcfg.sh --proxy=10.1.2.3 update [WAR_LOCATION]

By default, the initial version that you deploy to a service is automatically configured to receive 100% of traffic. However, all subsequent versions that you deploy to the same service must be manually configured, otherwise they receive no traffic.

The tool automatically uses the application ID from your appengine-web.xml file. However, many of our sample applications omit <application> from the appengine-web.xml file, as well as <version>. Therefore, you must ensure that a Cloud Platform project ID is specified for the application ID along with the version ID of your choice, for example:

Windows

appengine-java-sdk\bin\appcfg.cmd -A [YOUR_PROJECT_ID] -V [YOUR_VERSION_ID] update [WAR_LOCATION]

Mac / Linux

./appengine-java-sdk/bin/appcfg.sh -A [YOUR_PROJECT_ID] -V [YOUR_VERSION_ID] update [WAR_LOCATION]

Deploying multiple service applications

When your application is factored into multiple services, you can deploy and update individually targeted services or all the services simultaneously. Deploying updates to services can include updating individual configuration files or updating the source code in the corresponding versions.

For example, you can deploy and create two versions in App Engine, where each version runs in their own service. The first version serves as the frontend service and the other as the backend of your app. You can then deploy individual configuration files to update only the settings of a service. You can also choose to deploy a new version to a service in order to update the source code of the frontend, backend, or both simultaneously.

Requirements for multiple services

You use the same deployment commands for deploying and updating the multiple services of your application with the following requirements:

  • You must initially deploy a version of your app to the default service before you can create and deploy subsequent services.

  • You must specify the ID of your service in the appengine-web.xml configuration file of the corresponding version. To specify the service ID, you include the module: [YOUR_SERVICE_ID] element definition in each configuration file. By default, excluding this element definition from your configuration file deploys the version to the default service.

  • You must specify all the corresponding appengine-web.xml configuration files in your deployment command to simultaneously deploy multiple services. The default service must be listed first.

To deploy multiple services

From the root directory of the application where the configuration files are located, you run the deployment command and specify the relative paths and file names for each service's appengine-web.xml file:

Windows

appengine-java-sdk\bin\appcfg.cmd update [DEPLOYMENTS]

Mac / Linux

./appengine-java-sdk/bin/appcfg.sh update [DEPLOYMENTS]

Where [DEPLOYMENTS] is one or more configuration file's path and name. You separate each configuration file that you specify with a single white space.

Example

Windows

appengine-java-sdk\bin\appcfg.cmd update [WAR_LOCATION] [SERVICE1_WAR_LOCATION] [MOD2_WAR_LOCATION]

Mac / Linux

./appengine-java-sdk/bin/appcfg.sh update [WAR_LOCATION] [SERVICE1_WAR_LOCATION] [MOD2_WAR_LOCATION]

You will receive verification via the command line as each service is successfully deployed.

Updating indexes

To create or update the indexes that your app's use, you upload the datastore-indexes.xml configuration file to Cloud Datastore. Indexes that don't exist yet are created after that configuration file is uploaded.

It can take a while for Cloud Datastore to create all the indexes and therefore, those indexes won't be immediately available to App Engine. If your app is already configured to receive traffic, then exceptions can occur for queries that require an index which is still in the process of being built.

To avoid exceptions, you must allow time for all the indexes to build, for example:

  • Upload the index.xml configuration file to Cloud Datastore before you deploy your version:

    1. Upload the index.xml file to Cloud Datastore:

      appcfg.sh update_indexes [YOUR_APP_DIR]
      

    2. Use the Cloud Platform Console to monitor the status of all your indexes:

      Go to the Datastore page

    3. After all your indexes are built, deploy the new version to App Engine.

  • Build your indexes before migrating or splitting traffic to your version:

    1. Define a new version ID in your app's appengine-web.xml file.
    2. Deploy the new version.
    3. Use the Cloud Platform Console to monitor the status of all your indexes:

      Go to the Datastore page

    4. After all your indexes are built, use the Cloud Platform Console to migrate or split traffic to your version:

      Go to the Versions page

For more information about indexes, see Configuring Datastore Indexes.

Troubleshooting

The following are common error messages that you might encounter:

Command not found

If you did not create symlinks for the appcfg.sh or dev_appserver.sh tools when you installed the App Engine SDK, you might need to specify the full directory path to run the tool, for example: [PATH_TO_APP_ENGINE_SDK]/appcfg.sh or [PATH_TO_APP_ENGINE_SDK]/dev_appserver.sh .

Import Error

If you installed both the Google Cloud SDK as well as the original App Engine SDK, the entries to your PATH might conflict with one another and cause import errors. If you received errors when running Cloud SDK commands, try explicitly using the original App Engine SDK. You can move the entry for the original App Engine SDK to earlier in your PATH so that those commands have priority. Alternatively, you can run the command by specifying the full directory path: [PATH_TO_APP_ENGINE_SDK]/dev_appserver.sh.
Tip: On Linux or Mac, you can run which dev_appserver.py to determine which SDK is first in your PATH.

[400] The first service (module) you upload to a new application must be the 'default' service (module)

Before you can deploy and create the multiple services of your application, you must first deploy and create the default service. For details about how to deploy a version to the default service, see Deploying multiple service applications.

Too Many Versions (403)

App Engine has a limit on the number of deployed versions of your application. These differ for free applications and deployed applications. You can use the Cloud Platform Console to delete an older version and then upload your latest code.

You do not have permission to modify this app (403)

This can occur when the account that you are authenticated as does not have permission to deploy to the application ID that is specified in your command or in your appengine-web.xml. Check your application ID is accurate and matches the value of your Cloud Platform Console project ID. Next, check the project permissions in the console and verify that your account is listed with a sufficient permission level to allow for deploying apps. If the account permission and project ID appear correct, you can try to force a reauthentication of your SDK by removing the .appcfg_oauth2_tokens file from your home directory and retry the deployment commands.

What's next

Send feedback about...

App Engine standard environment for Java