Recently, I tried using GAE (Google App Engine) for the first time, but I was addicted to the initial project construction, so I wrote it as an article. The goal of this article is to be able to build and deploy with Maven.
This article assumes the following as the development environment.
--GAE uses standard environment --Java + Maven is used for initial project construction, build, and deployment --Eclipse is used as the development editor
It is assumed that the account registration and project creation on the cloud side have been completed. First, create an initial project in Maven. According to the GAE documentation (https://cloud.google.com/appengine/docs/standard/java/tools/maven?hl=ja), you can do the following:
mvn archetype:generate -Dappengine-version=1.9.71 \
-Djava8=true -DCloudSDK_Tooling=false \
-Dapplication-id=your-app-id \
-Dfilter=com.google.appengine.archetypes:
For your-app-id, specify the project ID of the GAE to deploy to. I just did the above without thinking and got hooked on it later. Even if you make a mistake in the project ID, you can correct it later.
1: remote -> com.google.appengine.archetypes:appengine-flexible-archetype (A basic Java application with Google App Engine flexible.)
2: remote -> com.google.appengine.archetypes:appengine-skeleton-archetype (A skeleton application with Google App Engine)
3: remote -> com.google.appengine.archetypes:appengine-standard-archetype (A basic Java application with Google App Engine Standard)
4: remote -> com.google.appengine.archetypes:endpoints-skeleton-archetype (A skeleton project using Cloud Endpoints Frameworks with Google App Engine Standard)
5: remote -> com.google.appengine.archetypes:guestbook-archetype (A guestbook application with Google App Engine)
6: remote -> com.google.appengine.archetypes:hello-endpoints-archetype (A simple starter application using Cloud Endpoints Frameworks with Google App Engine Standard)
7: remote -> com.google.appengine.archetypes:skeleton-archetype (Archetype with a README about Google App Engine archetypes)
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): :
I'm asked for archtype, but I chose 3: appengine-standard-archetype because it's a standard environment. 2: appengine-skeleton-archetype is almost the same as 3. 4: If you select endpoints-skeleton-archetype, you can create something like a REST application.
You will be asked for groupId, artifactId, package, etc., so if you enter them in a timely manner, a Maven project will be created.
If you want to modify the project ID, modify \ <appID > under \ <build > \ <plugins >. This is the {your-app-id} part below. If this cannot be set to the correct value, the deployment will fail. Specify the version in \ <version >.
<plugin>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>1.9.71</version>
<configuration>
<appId>{your-app-id}</appId> <!-- Override appengine-web.xml <project> -->
<version>1</version>
...
</configuration>
</plugin>
Add the required libraries. I added the following to use gcs (Google Cloud Storage). Since gcs-client has many dependent libraries, it is helpful to do it with Maven.
<dependency>
<groupId>com.google.appengine.tools</groupId>
<artifactId>appengine-gcs-client</artifactId>
<version>0.8</version>
</dependency>
Install Google Cloud Tools for Eclipse from the Eclipse Marketplace.
Import the created Maven project from File-> Import-> Existing Maven Projects in Eclipse. Please note that mvn eclipse: eclipse does not work well.
When looking for GAE related articles, many of them say that application settings are described in app.yaml, but when using Java in the GAE standard environment, it is generally described in appengine-web.xml. It seems to be the target. I have modified the following items:
item | Description |
---|---|
ssl-enabled | Set to true if only https is used. |
static-files | Specify a static file.(Request processing for static files does not consume instance time) |
In addition, there are setting items related to scaling. See the appengine-web.xml Reference for more information.
Run the following to run the app in your local environment.
mvn appengine:run
The following describes the points to note when executing in the local environment.
Appengine-api-1.0-sdk is used when using gae's API, but pom.xml says \ <scope > provided \ </ scope > and is included in the app itself. not. In the local environment, appengine-api-1.0-sdk does not exist in the common library, so it must be included in the app itself. Therefore, temporarily comment out \ <scope > provided \ </ scope >. Please note that you need to undo the comment out when deploying.
If you access http: // localhost: 8080 / _ah / admin, you can check the status of Google Cloud Storage (emulation) that operates locally. (Please change the port number according to your environment) At the time of writing this article, it was not possible to make corrections only by viewing the data.
You can deploy to GAE below.
mvn appengine:deploy
If the account is not linked, you need to open a browser, log in to Google, and enter the displayed token in the console where the above command is being executed.
-Using Apache Maven and App Engine Plugin (based on App Engine SDK) -appengine-web.xml reference
Recommended Posts