Building GAE Projects with Maven
Apply for Service
You can apply service at https://cloud.google.com with your Visa or Master Card. To apply for a service, you need to sign in to your Google account.
Google will offer a $ 300 voucher after subscribing to the service. A $ 300 service is free for up to one year after application. If you spend $ 300 or a year, Google asks if you want to continue using the service. If you confirm that you will continue to use the service, Google will initialize the service cost to zero, and any subsequent service charges will be automatically credited to the card you enrolled 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.
If you enter a project name, the project ID is made in project name-number format. If you name the project uniquely, the project name and project ID can be the same. Remember the project ID.
Set up the project
Install the latest version of Java. See Java Install for installation instructions.
Install the latest version of Maven. See Maven Install for installation instructions.
To add the Cloud SDK bin path to the environment variable PATH on Windows, run the following as administrator:
Install the app-engine-java component. you need to open the command prompt as an administrator.
gcloud components install app-engine-java
Initialize gcloud with the following command:
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 in which the instance will be created, usually a location close to the service area. See https://cloud.google.com/compute/docs/regions-zones/ for more information about zone.
Download the Eclipse installer file from http://www.eclipse.org. Unzip and run the Eclipse installer named eclipse-inst in the generated directory and install Eclipse for Java EE Developers.
Download the latest binary file from https://git-scm.com and unzip it. Unzip and move the generated directory to the appropriate location and add the path to the Git bin directory to your PATH environment variable.
Create a guestbook archetype
Execute the following command in the workspace.C:\ Command Prompt
C:\Lab>mvn archetype:generate -Dappengine-version=1.9.76 -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: 22.214.171.124 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.76 [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.76 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.76 [INFO] project created from Archetype in dir: C:\Lab\guestbook [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS
When the build is complete, a subfolder with the same name as the artifactId value is created. Since you gave the artifactId value to guestbook, a guestbook subfolder is created. Go to the guestbook folder and run the following command.
C:\ Command Prompt
C:\Lab>cd guestbook C:\Lab\guestbook>mvn clean package
The command for local testing is mvn appengine:run.C:\ Command Prompt
If you see "Dev App Server is now running", visit http://localhost:8080 in your web browser and test. When the test is finished, press Ctrl + C to exit.
Open pom.xml and modify "your-app-id" to real project id in "<!-- <app.deploy.project>your-app-id</app.deploy.project> -->" then Remove comment.
<properties> <app.deploy.project>real project id</app.deploy.project>
To deploy the app to the server, run mvn appengine:deploy.C:\ Command Prompt
If the build is successful, visit https://your-project-id.appspot.com. Unlike local tests, you will encounter the following server error: However, if you try again after a few minutes, the error disappears and you can see the guestbook.
The reason for the error is that it was requested before the datastore index was created. The data store index takes a few minutes to be created. The error that occurred because there is no index can be checked in the log of Google's cloud console log as follows.
The datastore index can be found in the Google Cloud Console.
Create a Git repository
Create a personal repository in the Google Cloud as follows:
gcloud source repos create firstGaePjt
The firstGaePjt repository was created in the Google cloud.
Create a local repository as follows:
C:\Lab>gcloud source repos clone firstGaePjt
The firstGaePjt local repository was created on the development system.
Since the remote repository is empty, it is natural to see the message "warning: You appear to have cloned an empty repository.". The generated firstGaePjt directory is where the source is located. Copy all the files in C:\Lab\guestbook to the C:\Lab\firstGaePjt directory.
You can now manage guestbook sources with git.
git add . -A git commit -m "First Commit" git push origin masterReferences