Using Apache Maven and the App Engine Plugin (Cloud SDK-based)

This page explains how to manage an App Engine project using Apache Maven, a software project management and comprehension tool. It is capable of building WAR files for deployment into App Engine. Google provides a plugin and Maven Archetypes which are supported by Maven 3.3.9 and greater.

When you use Maven, you don't need to download the Java libraries from the Google App Engine SDK. Maven does that for you. You can also use Maven to test your app locally and upload (deploy) it to production App Engine.

Setting up Maven

Configuring Java

  1. If you don't have Java, download and install it.

  2. You can use Java 7 or Java 8, but you must use Java 7 bytecode level. If you are using Java 8, configure your app to compile to 1.7 bytecode in your project's pom.xml:

    <properties>  <!-- App Engine Standard currently requires Java 7 -->

Installing Maven 3.3.9+

  1. To determine whether Maven is installed and which version you have, invoke the following command:

     mvn -v
  2. If you don't have the proper version of Maven installed:

    1. Download Maven 3.3.9 or greater from the Maven website.
    2. Install Maven 3.3.9 or greater on your local machine.

Installing and configuring Google Cloud SDK and App Engine Java SDK

To use the Maven plugin, you must install and configure Cloud SDK and App Engine Java SDK:

  1. Install Cloud SDK.

Note: When you install the Cloud SDK, you must authorize it to access Google Cloud Platform. The installation instructions above include instructions for running gcloud init, but depending on your needs, you might want to run gcloud auth login (which authorizes the user account without performing setup steps) or gcloud beta auth application-default login (to use a service account) instead. For more information, see Authorizing Cloud SDK Tools.

  1. Install the Cloud SDK app-engine-java component:

    gcloud components install app-engine-java
  2. Install the App Engine SDK for Java and add the directory to your PATH.

Using Eclipse with a Maven project (optional)

A Maven project has a different layout than an Eclipse project. If you wish to use a Maven project with Eclipse, you should use Eclipse for Java Enterprise Edition (EE) and one of the following approaches:

Using Maven

Adding the App Engine plugin to an existing project (optional)

To use the Google App Engine Maven plugin to an existing Maven project, add the following into the plugins section in the project pom.xml file:


Choosing an archetype

Maven Archetypes allow users to create Maven projects using templates that cover common scenarios. App Engine takes advantage of this Maven feature to provide some useful App Engine archetypes at Maven Central. Select an App Engine archetype appropriate for your app:

Application Type Artifact Description
App Engine app* guestbook-archetype Generates the guestbook demo sample, complete and ready to run and test.
App Engine app* appengine-skeleton-archetype Generates a new, empty App Engine project ready for your own classes and resources, but with required files and directories.

Creating a new project

During project creation, Maven prompts you to supply groupId, artifactId, version, and the package for the project.

Term Meaning
groupId A namespace within Maven to keep track of your artifacts. When people consume your project in their own Maven Project, it will serve as an attribute of the dependency they will end up specifying.
artifactId The name of your project within Maven. It is also specified by consumers of your project when they depend on you in their own Maven projects.
version The initial Maven version you want to have your project generated with. It's a good idea to have version suffixed by -SNAPSHOT because this will provide support in the Maven release plugin for versions that are under development. For more information, see the Maven guide to using the release plugin.
package The Java package created during the generation.

To use App Engine Maven archetypes to create an App Engine App:

  1. Get a project ID from the Cloud Platform Console.

  2. Change to the directory where you want to build the project.

  3. Invoke the following Maven command:

    mvn archetype:generate -Dappengine-version=1.9.42 -Dproject-id=[YOUR-PROJECT_ID]


    • appengine-version is set to the most recent App Engine Java SDK version.
    • project-id is set to the Cloud Platform Console project ID used for your app.
  4. If you want to create the complete, ready-to-run guestbook sample app, supply the number corresponding to

    If you want to create an empty project that contains the required directory structure and files, ready for your own classes, supply the number corresponding to archetype.

  5. Select the most recent version from the displayed list of available archetype versions by accepting the default.

  6. When prompted to Define value for property 'groupId', supply the desired namespace for your app; for example, com.mycompany.myapp.

  7. When prompted to Define value for property 'artifactId', supply the project name; for example, myapp or guestbook.

  8. When prompted to Define value for property 'version', accept the default value.

  9. When prompted to Define value for property 'package', supply your preferred package name (or accept the default). The generated Java files will have the package name you specify here.

  10. When prompted to confirm your choices, accept the default value (Y).

  11. Wait for the project to finish generating. then change directories to the new project directory, for example guestbook/.

  12. Build the project by invoking

        mvn clean package
  13. Wait for the project to build. When the project successfully finishes you will see a message similar to this one:

        [INFO] --------------------------------------------------
        [INFO] --------------------------------------------------
        [INFO] Total time: 1:16.656s
        [INFO] Finished at: 2016-08-04T16:18:24-07:00
        [INFO] Final Memory: 16M/228M
        [INFO] --------------------------------------------------
  14. If you created the sample Guestbook demo app using the guestbook-archetype artifact:

    1. Test the application locally in the development server:

      mvn appengine:run
      Wait for the dev server to start up. When it finishes starting up, you
      will see a message similar to this:
           [INFO] GCLOUD: INFO: Module instance default is running at http://localhost:8080/
           [INFO] GCLOUD: Jul 27, 2016 11:44:19 AM startup
           [INFO] GCLOUD: INFO: The admin console is running at http://localhost:8080/_ah/admin
           [INFO] GCLOUD: Jul 27, 2016 11:44:19 AM doStart
           [INFO] GCLOUD: INFO: Dev App Server is now running

    2. Visit the application at the default URL and port http://localhost:8080/ used by the development server. You will see the guestbook demo app.

    3. To shut down the app and the development server, press Control-C.

  15. If you created a new, empty app using the appengine-skeleton-archetype artifact:

    1. Before starting to code your own classes for the app, familiarize yourself with the basic project layout and the required project files: inside the directory where you created the project, you'll have a subdirectory named myapp, which contains a pom.xml file, the src/main/java subdirectory, and the src/main/webapp/WEB-INF subdirectory:

      Maven Project Layout

      • Add your own application Java classes to src/main/java/...
      • Configure your application using the file src/main/webapp/WEB-INF/appengine-web.xml
      • Configure your application deployment using the file src/main/webapp/WEB-INF/web.xml
    2. Create your application Java classes and add them to src/main/java/.../ For more information, see Getting Started

    3. Add the UI that you want to provide to your app users. For more information, see Adding Application Code and UI.

    4. The artifact you used to create the project has done the basic src/main/webapp/WEB-INF/appengine-web.xml configuration for you. However, for more advanced configuration, you may need to edit this file. For more information, see Configuring with appengine-web.xml.

    5. Edit the file src/main/webapp/WEB-INF/web.xml to map URLs to your app handlers, specify authentication, filters, and so forth. This is described in detail in The Deployment Descriptor.

Managing, testing, and deploying a Maven project

Compiling and building your project

To build an application created with the Maven App Engine archetypes:

  1. Change to the main directory for your project, for example, guestbook/.

  2. Invoke Maven:

    mvn clean package
  3. Wait for the project to build. When the project successfully finishes you will see a message similar to this one:

     Total time: 10.724s
     Finished at: 2016-08-04T16:18:24-07:00
     Final Memory: 24M/213M
  4. Optionally, test the application using the following procedure.

Testing your application with the development server

During the development phase, you can run and test your application at any time in the development server by invoking the App Engine Maven plugin.

To test your app:

  1. If you haven't already done so, build your app:

    mvn clean package
  2. Change directory to the top level of your project (for example, to myapp) and invoke Maven:

    mvn appengine:run

    Wait for the s