Getting Started: Setting Up Your Development Environment

Learn how to set up your build environment for app development and deployment to Google App Engine Standard. The supported Java development and build environments are IntelliJ IDEA, Eclipse, Apache Maven, and Gradle.

This guide will show you how to:

  • Install the Google Cloud SDK command-line tool.
  • Install and configure App Engine plugins for Eclipse, IntelliJ, Gradle, and Maven.
  • Create a new App Engine project.

Installing required SDKs

  1. If you haven't already installed Java SE 8 SDK, install the Java SE 8 Development Kit (JDK).

  2. Install the latest version of the Google Cloud SDK.

    Install Google Cloud SDK

  3. Install the App Engine Java component:

    gcloud components install app-engine-java
    
  4. Authorize your user account:

    gcloud auth application-default login
    
  5. Optionally, to create a service account run gcloud auth activate-service-account --key-file=your_key.json. For more information, see Authorizing Cloud SDK Tools.

Configuring your development environment

Eclipse

Before you begin:

  1. Install Eclipse IDE for Java EE Developers, version 4.6 or later:

    Download Eclipse

  2. If you have the Google Plugin for Eclipse installed, complete the migrating from GPE procedures.

Install the plugin:

  1. Drag the install button into your running Eclipse workspace:

    Drag to your running Eclipse workspace.

    Or from inside Eclipse, select Help > Eclipse Marketplace... and search for Google Cloud.

  2. Restart Eclipse when prompted.

IntelliJ

Before you begin:

  1. Sign in to your Google Account.

    If you don't already have one, sign up for a new account.

  2. Select or create a GCP project.

    Go to the Manage resources page

  3. Make sure that billing is enabled for your project.

    Learn how to enable billing

  4. Ensure that the following software is installed on your local system:

Install the plugin:

  1. From inside IDEA, open File > Settings. Or, on Mac OS X, open IntelliJ IDEA > Preferences.
  2. In the navigation pane, select Plugins.
  3. Click Browse repositories.
  4. In the dialog that opens, select Google Cloud Tools.
  5. Click Install.
  6. Click Close.
  7. Click OK in the Settings dialog.
  8. Click Restart.
  9. Configure the project JDK:
    1. Open File > Project Structure. Or on Mac OS X open IntelliJ IDEA > Project Structure.
    2. Choose Project Settings > Project.
    3. If the Project JDK is missing, click New... and choose a JDK.

Gradle

  1. Install Gradle v3.4.1 or newer

  2. Install git

Maven

  1. Download Maven 3.5 from the Maven website.

  2. Install Maven 3.5 on your local machine.

Creating a new App Engine project

Eclipse

  1. Click the Google Cloud Platform toolbar button .

  2. Select Create New Project > Google App Engine Standard Java Project.

  3. Enter a Project name and (optionally) a Java package.

  4. To create a Maven-based App Engine project, check Create as Maven Project and enter a Maven Group ID and Artifact ID.

  5. Select the libraries (App Engine API, Google Cloud Endpoints, and Objectify) to include in the project.

  6. Click Finish.

The wizard generates a native Eclipse project, with a simple servlet, that you can run and deploy from the IDE.

IntelliJ

  1. Choose File > New > Project to display the New Project dialog.

  2. Choose Java in the left panel.

  3. In the Additional Libraries and Frameworks section, check the Google App Engine box for your environment.

  4. Select the additional libraries you want to add to the classpath of your application. The Servlet API is selected by default.

  5. Click Next.

  6. Enter a Project name.

  7. Enter a Project location if you do not want to keep the default.

  8. Update the fields in the More Settings section if you do not want to keep the defaults.

  9. Click Finish.

Gradle

  1. Create a new directory.

  2. Initialize the new project in the created directory:

    gradle init --type java-library;
    mkdir -p src/main/webapp/WEB-INF;
    rm src/main/java/Library.java src/test/java/LibraryTest.java
    

    Gradle will create a skeleton directory structure with two empty classes that are removed in the final rm command.

  3. Add the following to your build.gradle file to add App Engine Gradle tasks, Maven repositories, the App Engine Gradle plugin, dependencies, and task configuration:

    buildscript {      // Configuration for building
      repositories {
        jcenter()      // Bintray's repository - a fast Maven Central mirror & more
        mavenCentral()
      }
      dependencies {
        classpath 'com.google.cloud.tools:appengine-gradle-plugin:1.+' // Latest 1.x.x release
        classpath 'org.akhikhl.gretty:gretty:+'
      }
    }
    
    repositories {   // repositories for JARs you access in your code
      maven {
        url 'https://maven-central.storage.googleapis.com'             // Google's mirror of Maven Central
      }
    
    //maven {
    //  url 'https://oss.sonatype.org/content/repositories/snapshots' // SNAPSHOT repository if needed
    //}
    
      jcenter()
      mavenCentral()
    }
    
    apply plugin: 'java'
    apply plugin: 'war'
    apply plugin: 'org.akhikhl.gretty'
    apply plugin: 'com.google.cloud.tools.appengine'
    
    dependencies {
      providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
      providedCompile 'com.google.appengine:appengine:+'
    // Add your dependencies here.
    
    }
    
    gretty {
        httpPort = 8080
        contextPath = '/'
        servletContainer = 'jetty9'  // What App Engine Flexible uses
    }
    
    appengine {
    
      deploy {   // deploy configuration
        stopPreviousVersion = true  // default - stop the current version
        promote = true              // default - & make this the current version
      }
    
    }
    
    group = 'com.example.appengine'   // Generated output GroupId
    version = '1.0-SNAPSHOT'          // Version in generated output
    
    sourceCompatibility = 1.8
    targetCompatibility = 1.8

Maven

To create an App Engine App:

  1. Create a new directory.

  2. Initialise the new project in the created directory:

     mvn archetype:generate -Dappengine-version=1.9.59 -Djava8=true -DCloudSDK_Tooling=true -Dapplication-id=your-app-id -Dfilter=com.google.appengine.archetypes:
    
    1. Set -Dappengine-version to the most recent version of the App Engine SDK for Java, and application-id to the ID of your GCP project.

    2. Set -Djava8=true to deploy the project in the Java 8 runtime.

    3. Set -DCloudSDK_Tooling=true to use Cloud SDK tooling.

  3. When prompted to choose an archetype, choose the value 2 for the App Engine skeleton archetype. This creates an empty project that contains the required directory structure and files.

  4. When prompted for version, press ENTER to select the default most recent version.

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

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

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

  8. 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.

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

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

  11. Add the Cloud SDK-based plugin to your project's pom.xml file.

    <build>
        <plugins>
           [...]
              <plugin>
                <groupId>com.google.cloud.tools</groupId>
                <artifactId>appengine-maven-plugin</artifactId>
                <version>1.3.1</version>
                <configuration>
                    <project>your-project-ID-goes-here</project>
                    <version>1</version>
                </configuration>
              </plugin>
           [...]
        </plugins>
    </build>
    
  12. Specify the target Google Cloud Platform project ID and the service and version in the plugin configuration.

What's next

Now that your development environment is set up, you can get started with developing and deploying Java apps to App Engine.

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

Send feedback about...

App Engine standard environment for Java