Google App Engine
Feedback on this document

Configuring the Maven Project for Endpoints

Before adding code and testing it, you need to make sure the project has all the necessary dependencies and project settings.

Adding the Project ID to appengine-web.xml

In the project directory you created, edit the file src/main/webapp/WEB-INF/appengine-web.xml. In the <application> field, copy the project ID (App Engine app ID) value you obtained following the Setup instructions to create an App Engine app. The backend API will be deployed to this project ID. Notice that appengine-web.xml also contains a <version> field where you specify the version to deploy to. For now, keep this at 1. (For more information about deploying to application versions, see Deploying to multiple App Engine app versions.)

Setting required properties entries

Change directory to the project directory you created and open the pom.xml file with an editor. Note the <properties> entries in the default pom.xml file:

    <modelVersion>4.0.0</modelVersion>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>

<groupId>com.google.devrel.samples.helloendpoints</groupId>
<artifactId>helloendpoints</artifactId>

<properties>
    <appengine.app.version>1</appengine.app.version>
    <appengine.target.version><!--Latest App Engine Java SDK version--></appengine.target.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

In <properties>, change the appengine.target.version value to the latest App Engine Java SDK version: 1.8.8.

Note that <packaging> must be set to war.

Setting required runtime dependencies

In the default generated pom.xml file, replace all of the Compile/runtime dependencies entries with the following:

    <!-- Compile/runtime dependencies -->
<dependency>
    <groupId>com.google.appengine</groupId>
    <artifactId>appengine-api-1.0-sdk</artifactId>
    <version>${appengine.target.version}</version>
</dependency>
<dependency>
    <groupId>com.google.appengine</groupId>
    <artifactId>appengine-endpoints</artifactId>
    <version>${appengine.target.version}</version>
</dependency>
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>javax.inject</groupId>
    <artifactId>javax.inject</artifactId>
    <version>1</version>
</dependency>

Note that javax.inject is not absolutely required, but it is commonly used, since any parameter injection using @Named in Endpoints must use javax.inject for this. It is required for this tutorial.

Setting Required Plugin Configuration

You need to modify the default plugin configuration for:

  • The maven-war-plugin.
  • The appengine-maven-plugin.

Setting maven-war-plugin

Replace the default maven-war-plugin configuration entirely with the following:

    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.3</version>
    <configuration>
        <webXml>${project.build.directory}/generated-sources/appengine-endpoints/WEB-INF/web.xml</webXml>
        <webResources>
            <resource>
                <!-- this is relative to the pom.xml directory -->
                <directory>${project.build.directory}/generated-sources/appengine-endpoints</directory>
                <!-- the list has a default value of ** -->
                <includes>
                    <include>WEB-INF/*.discovery</include>
                    <include>WEB-INF/*.api</include>
                </includes>
            </resource>
        </webResources>
    </configuration>
</plugin>

Setting appengine-maven-plugin

Replace the default appengine-maven-plugin configuration entirely with the following:

    <plugin>
    <groupId>com.google.appengine</groupId>
    <artifactId>appengine-maven-plugin</artifactId>
    <version>${appengine.target.version}</version>
    <configuration>
        <enableJarClasses>false</enableJarClasses>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>endpoints_get_discovery_doc</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Rebuilding the project with the new pom.xml settings

When you finish modifying the pom.xml file, rebuild the project by invoking Maven as follows:

mvn install

Next...

At this point, you are ready to write backend code.

Continue to Writing the API: A Simple GET.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.