Using Apache Maven and the App Engine Plugin

Apache Maven is a build automation tool for Java. It is capable of building WAR files for deployment into App Engine. The App Engine team provides both a plugin and Maven Archetypes for the purpose of speeding up development.

Setting up Maven

To use Maven in the flexible environment:

  1. Determine whether Maven is installed and which version you have, by invoking the following command:

    mvn -v

    This command should display a long string of information beginning with Apache Maven 3.3.9.

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

    1. Download Maven 3.3.9 or greater.
    2. Install Maven 3.3.9 or greater.

Setting up and validating your GCP project

You need to set up your GCP project and install the Cloud SDK:

  1. Use the Google Cloud Platform Console to create and set up your GCP project:

    Go to App Engine

    1. Select or create a new GCP project.
    2. Follow the prompts to ensure that an App Engine application exists and billing is enabled:
      1. If you need to create an App Engine application for your project, you are prompted to select the region where you want your App Engine application located.
      2. If you need to enable billing for your project, you are prompted to create a new billing account or select an existing account.
    3. The Dashboard opens after your App Engine application has been created and billing has been enabled in your project.
  2. Install and initialize the Google Cloud SDK.

    If you already have the gcloud tool installed and want to configure it to use a GCP project ID other than the one that you initialized it to, see Managing Cloud SDK Configurations.

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

    gcloud components install app-engine-java

Optional sample app

If you want to start with a sample Java app, you can use this GitHub project.

Adding the App Engine Maven and Eclipse Jetty Maven plugins

To develop and deploy your application, use the Google App Engine Maven plugin. To test your application quickly without creating a WAR file, use the Jetty Maven plugin.

To use these plugins in an existing Maven project, add the following into the plugins section in the project pom.xml file:


Compile and build your project using Maven

To build an Java App Engine Web Application using Maven with its pom.xml file:

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

  2. Invoke Maven:

    mvn 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-07-29T12:13:36-07:00
     Final Memory: 24M/213M
  4. Optionally, run and test the application locally using the Jetty web development server, as described in the next section.

Running and testing your app

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

To run your app in the development server:

  1. Build your app if you haven't already done so:

    mvn package
  2. Change directory to the top level of your project (for example, to myapp), and run your app by invoking Maven:

    mvn jetty:run
  3. Wait for the server to start and use your browser to visit http://localhost:8080/ to access your app.

  4. Shut down the app and the development server by pressing Control+C.

Deploying your app

After you add the App Engine Maven plugin to your project's pom.xml file, you can deploy your application:

mvn appengine:deploy

The appengine:deploy goal and all other goals in the App Engine Maven plugin have associated parameters that you can use. For a complete list, see App Engine Maven Plugin Goals and Parameters.

What's next

Was this page helpful? Let us know how we did:

Send feedback about...

App Engine flexible environment for Java docs