Building GAE Projects with Maven

Apply for Service

While signing in to your Google Account, you can apply for the service at https://cloud.google.com with your Visa or MasterCard. Google offers a $300 voucher for first-time users. The voucher is valid for one year. After $300 worth of service, or after one year, Google will ask you if you want to continue using the service. Upon confirmation that the user will continue to use the service, Google will reset the service fee to zero. All subsequent service charges will be automatically charged to the card registered at the time of application.

Create my project

Once you've completed your application, go back to https://cloud.google.com, and you'll see a GO TO CONSOLE button. Click this button to go to the web console screen. The first thing to do on the web console screen is to create a project. Click the Create Project menu next to Google Cloud Platform in the top left corner. The console system generates a project ID in the project name-number format when you enter a project name. If others do not use the project name, the console system creates the same project ID as the project name. Anyway, what we need to remember is the project ID.

Project name, Project ID

Set up the project

Java

On Windows, install Java 8.
On Linux, install Java 11.
See Java Install for installation instructions.

Maven Install

Install the latest version of Maven.
See Maven Install for installation instructions.

Cloud SDK

Install the Cloud SDK referring to the address: https://cloud.google.com/sdk/docs/quickstart-windows

Add the Cloud SDK bin path to the environment variable PATH on Windows with the following command as an administrator:

.\google-cloud-sdk\install.bat

Install the app-engine-java component with the following command as an administrator:

gcloud components install app-engine-java

Initialize gcloud with the following command:

gcloud init

Initialize the project and zone of Google Compute Engine. (You should create the project in the Google Cloud Console before running the command, we have already done this) Zoning specifies the region where AWS will create the instance, usually close to the service area. See https://cloud.google.com/compute/docs/regions-zones/ for more information about the zone.

Eclipse

Download the Eclipse installation file from http://www.eclipse.org. Unzip the downloaded file and run the eclipse-inst in the generated directory. Install Eclipse for Java EE Developers from the list of programs.

Git

Download the latest binary file from https://git-scm.com and unzip it. Move the generated directory to the appropriate location and add the path to the Git bin directory to your PATH environment variable.

guestbook archetype

Create a guestbook archetype with the following command:

C:\ Command Prompt
C:\Lab>mvn archetype:generate -Dappengine-version=1.9.84 -Dfilter=com.google.appengine.archetype:

Choose archetype:
1: remote -> com.google.appengine.archetypes:appengine-flexible-archetype
2: remote -> com.google.appengine.archetypes:appengine-skeleton-archetype
3: remote -> com.google.appengine.archetypes:appengine-standard-archetype
4: remote -> com.google.appengine.archetypes:endpoints-skeleton-archetype
5: remote -> com.google.appengine.archetypes:guestbook-archetype
6: remote -> com.google.appengine.archetypes:hello-endpoints-archetype
7: remote -> com.google.appengine.archetypes:skeleton-archetype (-)
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): : 5 
Choose com.google.appengine.archetypes:guestbook-archetype version: 
1: 1.7.4
2: 1.7.4.1
3: 1.7.5
4: 1.7.6
5: 1.7.7
6: 1.8.4
7: 2.0.0-1.9.10
8: 3.0.0-1.9.20
9: 3.0.1-1.9.21
10: 3.0.1-1.9.25
11: 3.0.2-1.9.38
12: 3.1.0-1.9.42
13: 4.0.0
14: 4.0.1
15: 4.0.2
Choose a number: 15: 14 
Define value for property 'groupId': : net.java_school.guestbook
Define value for property 'artifactId': : guestbook
Define value for property 'version':  1.0-SNAPSHOT: : 
Define value for property 'package':  net.java_school.guestbook: : 
[INFO] Using property: CloudSDK_Tooling = true
[INFO] Using property: appengine-version = 1.9.84
[INFO] Using property: application-id = your-app-id
[INFO] Using property: java8 = true
[INFO] Using property: service = default
Confirm properties configuration:
groupId: net.java_school.guestbook
artifactId: guestbook
version: 1.0-SNAPSHOT
package: net.java_school.guestbook
CloudSDK_Tooling: true
appengine-version: 1.9.84
application-id: your-app-id
java8: true
service: default
 Y: : 
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: guestbook-archetype:4.0.1
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: net.java_school.guestbook
[INFO] Parameter: artifactId, Value: guestbook
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: package, Value: net.java_school
[INFO] Parameter: packageInPathFormat, Value: net/java_school/guestbook
[INFO] Parameter: CloudSDK_Tooling, Value: true
[INFO] Parameter: groupId, Value: net.java_school.guestbook
[INFO] Parameter: service, Value: default
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: application-id, Value: your-app-id
[INFO] Parameter: package, Value: net.java_school.guestbook
[INFO] Parameter: artifactId, Value: guestbook
[INFO] Parameter: java8, Value: true
[INFO] Parameter: appengine-version, Value: 1.9.84
[INFO] project created from Archetype in dir: C:\Lab\guestbook
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS

When the build is complete, mvn creates a subfolder with the same name as the artifactId value. Since the artifactId value is a guestbook, Maven creates the guestbook subfolder.

Go to the guestbook folder.

C:\ Command Prompt
C:\Lab>cd guestbook

Run the following command.

C:\ Command Prompt
C:\Lab\guestbook>mvn clean package

Local test

Run the local test with the following command:

C:\ Command Prompt
C:\Lab\guestbook>mvn appengine:run

When you can see "Dev App Server is now running," visit http://localhost:8080 to test. For finishing the test, press Ctrl + C in the command prompt.

Remote Test

In your pom.xml, replace your-app-id in <!-- <app.deploy.project>your-app-id</app.deploy.project> --> with your actual project ID. Uncomment the "app.deploy.project" element.

<app.deploy.project>real project id</app.deploy.project>

Deploy the app to the server with the following command:

C:\ Command Prompt
C:\Lab\guestbook>mvn appengine:deploy

If the deployment completes without errors, visit https://your-project-id.appspot.com. Unlike local tests, server errors can occur.

First Server Error

In most cases, when you revisit after a few minutes, the error disappears, and you can see the guestbook.

First Remote Test

The reason for the error is that it was requested before Datastore created the index. You can confirm this error in the Log of the Google cloud console as follows.

log message

You can also see the datastore indexes in the Indexes of the Google Cloud Console.

datatore indexes

Create a Git repository

Create a personal repository in the Google Cloud as follows:

gcloud source repos create firstGaePjt

The above command makes AWS create the firstGaePjt repository in the Google cloud.

Create a local repository with the following command:

C:\Lab>gcloud source repos clone firstGaePjt

The above command creates the firstGaePjt repository on your system. Since the remote repository is empty, it is natural to see the message "warning: You appear to have cloned an empty repository.". The firstGaePjt directory on your system is where the source should be. So copy all files from C:\Lab\guestbook to the directory C:\Lab\firstGaePjt and upload the source to the remote repository with the following command:

git add . -A
git commit -m "First Commit."
git push origin master
References