Building a development environment with Maven on Google App Engine [Java]

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.

Development environment targeted by this article

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

Initial project construction

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.

Modify pom.xml

Modify project ID and version

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>

Library addition

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 Cound Tools in Eclipse

Install Google Cloud Tools for Eclipse from the Eclipse Marketplace.

Import to eclipse

Import the created Maven project from File-> Import-> Existing Maven Projects in Eclipse. Please note that mvn eclipse: eclipse does not work well.

Modify appengine-web.xml

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 in local environment

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.

Temporarily comment out provided for appengine-api-1.0-sdk

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.

Developer console

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.

Deploy

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.

reference

-Using Apache Maven and App Engine Plugin (based on App Engine SDK) -appengine-web.xml reference

Recommended Posts

Building a development environment with Maven on Google App Engine [Java]
Using properties files with Flexible Environment Java 8 on Google App Engine
Google App Engine development with Docker
Deploy a Python app on Google App Engine and integrate it with GitHub
Deploy a Django application on Google App Engine (Python3)
Google App Engine / Python development environment construction procedure (late 2014)
PIL with Python on Windows 8 (for Google App Engine)
Hello World with Google App Engine (Java 8) + Spring Boot + Gradle
Hello World with Google App Engine (Java 8) + Servlet API 3.1 + Gradle
Building a Jupyter Lab development environment on WSL2 using Anaconda3
Hello World with Google App Engine (Java 11) + Spring Boot + Gradle
Until building a Python development environment using pyenv on Ubuntu 20.04
Building a kubernetes environment with ansible 2
Building a Python environment on Mac
Java 1 1 support from Google App Engine
Building a virtual environment with Python 3
Use ndb.tasklet on Google App Engine
Building a kubernetes environment with ansible 1
How to connect to Cloud SQL PostgreSQL on Google Cloud Platform from a local environment with Java
Do you have any recommendations for a commentary book on Google App Engine / Python development?
[Google App Engine] Flow from development environment construction to application creation
[Pyenv] Building a python environment with ubuntu 16.04
Building a Python3 environment with Amazon Linux2
Easily build a development environment with Laragon
Building a LaTeX environment on Chrome OS
[Python] Run Flask on Google App Engine
Use external modules on Google App Engine
I can't deploy with google app engine
Building a Python development environment for AI development
Procedure for building a kube environment on amazon linux2 (aws) ~ (with bonus)
[Detailed version] Creating a comfortable Python environment with Google Compute Engine (Ubuntu 16.04)
Build a C language development environment with a container
Build a WardPress environment on AWS with pulumi
Building a python environment with virtualenv and direnv
Build a python environment with ansible on centos6
Building a Python environment with WLS2 + Anaconda + PyCharm
[Python] Build a Django development environment with Docker
Tweet (API 1.1) on Google App Engine for Python
Build a Python development environment on your Mac
Build a Django development environment with Doker Toolbox
Build a Kubernetes environment for development on Ubuntu
Building a Python environment on a Sakura VPS server
Create a Python virtual development environment on Windows
Build a Python development environment on Raspberry Pi
Get a quick Python development environment with Poetry
A story about building an IDE environment with WinPython on an old Windows OS.
Cross-compiling Raspberry Pi and building a remote debugging development environment with VS Code
Turn off optimization options in the Google App Engine Go development environment dev_appserver.py
Build a TensorFlow development environment on Amazon EC2 with command copy and paste
Build a GVim-based Python development environment on Windows 10 (3) GVim8.0 & Python3.6
Build a Django development environment using pyenv-virtualenv on Mac
Recommendation of building a portable Python environment with conda
Build a local development environment for Laravel6.X on Mac
Repairing a broken development environment with mavericks migration (Note)
Until you run a Flask application on Google App Engine for the time being
Create a comfortable Python 3 (Anaconda) development environment on windows
Create a python development environment with vagrant + ansible + fabric
Build a GVim-based Python development environment on Windows 10 (1) Installation
Build a Python development environment on Mac OS X
(Beginner) Basic usage of Datastore on Google App Engine
Web App Development Practice: Create a Shift Creation Page with Django! (Experiment on admin page)