Apache Maven is a build automation tool for Java, which builds WAR files for deployment into App Engine.
For faster deployments, use the following Maven tools:
- App Engine plugin
- Maven Archetypes
Setting up Maven
To use Maven:
Determine whether Maven is installed and which version you have by running the following command:
If you have Maven installed, a long string of information beginning with
Apache Mavenand followed by a version number such as
If you don't have Maven 3.5 or newer installed:
Setting up and validating your Google Cloud project
You need to set up your Google Cloud project and install Cloud SDK.
Use the Google Cloud Console to create and set up your Google Cloud project:
- Select or create a new Google Cloud project.
- Follow the prompts to ensure that an App Engine application
exists and billing is enabled:
- 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.
- Follow the prompts to create a new billing account or select an existing account.
- The Dashboard opens after your App Engine application has been created and billing has been enabled in your project.
If you already have the
gcloudtool installed and want to configure it to use a Google Cloud project ID other than the one that you initialized it to, see Managing Cloud SDK Configurations.
Install the Cloud SDK
gcloud components install app-engine-java
Adding the App Engine Maven and Eclipse Jetty Maven plugins
To use the plugin in an existing Maven project, add the following into the
plugins section in the project
<plugins> <plugin> <groupId>com.google.cloud.tools</groupId> <artifactId>appengine-maven-plugin</artifactId> <version>2.2.0</version> </plugin> <plugin> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>9.3.7.v20160115</version> </plugin> </plugins>
Compile and build your project using Maven
To build a Java App Engine app using Maven with its
Change to the main directory for your project, for example,
Wait for the project to build. When the project successfully finishes you will see a message similar to this one:
BUILD SUCCESS Total time: 10.724s Finished at: 2016-07-29T12:13:36-07:00 Final Memory: 24M/213M
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:
Build your app if you haven't already done so:
Change directory to the top level of your project (for example, to
myapp), and run your app by invoking Maven:
Wait for the server to start and use your browser to visit
http://localhost:8080/to access your app.
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
file, you can deploy your application:
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.