Learn how to set up your build environment for app development and deployment to the Java 8 runtime in the App Engine standard environment.
This guide will show you how to:
- Install the Google Cloud CLI.
- Install and configure the App Engine plugin for Maven. App Engine also provides plugins for Gradle, IntelliJ IDEA, and Eclipse, but this guide demonstrates the Maven plugin.
- Create a new App Engine project.
- Give permission to Cloud Build to enable building and deploying your app.
Installing required SDKs
If you haven't already installed Java SE 8 SDK, install the Java SE 8 Development Kit (JDK).
Install and initialize the latest version of the gcloud CLI.
Install the App Engine Java component:
gcloud components install app-engine-java
Authorize your user account:
gcloud auth application-default login
Configuring Maven in your development environment
Download Maven 3.5 or later from the Maven website.
Install Maven 3.5 or later on your local machine.
Creating a new App Engine project
To create an App Engine App:
Create a new directory.
Initialize 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:
Set
-Dappengine-version
to the most recent version of the App Engine SDK for Java, andapplication-id
to the ID of your Google Cloud project.Set
-Djava8=true
to deploy the project in the Java 8 runtime.Set
-DCloudSDK_Tooling=true
to use gcloud CLI tooling.
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.When prompted for version, press ENTER to select the default most recent version.
When prompted to
Define value for property 'groupId'
, supply the desired namespace for your app; for example,com.mycompany.myapp
.When prompted to
Define value for property 'artifactId'
, supply the project name; for example,myapp
.When prompted to
Define value for property 'version'
, accept the default value.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.When prompted to confirm your choices, accept the default value (
Y
).Wait for the project to finish generating, then change directories to the new project directory, for example
myapp/
.Add the gcloud CLI-based plugin to your project's
pom.xml
file.<build> <plugins> [...] <plugin> <groupId>com.google.cloud.tools</groupId> <artifactId>appengine-maven-plugin</artifactId> <version>2.4.4</version> <configuration> <projectId>your-project-ID-goes-here</projectId> <version>1</version> </configuration> </plugin> [...] </plugins> </build>
Specify the target Google Cloud Platform project ID and the service and version in the plugin configuration.
Give permission to Cloud Build
When you deploy your app, App Engine uses Cloud Build to build the app into a container and deploy the container to the runtime. Cloud Build does not have permission to deploy Java 8 apps by default, so you need to give Cloud Build permission to deploy apps in your project. The builds are created in the app's region.
What's next
Now that your development environment is set up, you can get started developing and deploying Java apps to App Engine.