App Engine Java 11 sample
This sample demonstrates how to use Cloud Spanner from the App Engine Standard with Java 11 environment.
Please feel free to report issues and send pull requests, but note that this application is not officially supported as part of the Cloud Spanner product.
Create a project in the Google Cloud Platform Console
If you haven't already created a project, create one now.
- Open the Cloud Console.
- In the drop-down menu at the top, select Create a project.
- Give your project a name.
- Make a note of the project ID, which might be different from the project name. The project ID is used in commands below.
If you like, you can activate a Cloud Shell for your project now. When using Cloud Shell, the Google Cloud SDK and Maven in the steps below will already be installed.
Set up your Google Cloud Platform Project
Install the Google Cloud SDK if it's not already available in your enviromment. Then run:
If this is your first time creating an App engine application:
gcloud app create
This sample uses the Apache Maven build system. If Maven isn't installed in your environment yet, download and install it. When you use Maven as described here, it will automatically download the required client libraries.
Google Cloud Shell Open JDK 11 setup:
To switch to Open JDK 11 in a Cloud Shell session, run:
# Select the usr/lib/jvm/java-11-openjdk-amd64/bin/java version. sudo update-alternatives --config java # Set the JAVA_HOME variable for Maven to pick the correct JDK: export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
Set up the sample
Clone the repository:
git clone https://github.com/cloudspannerecosystem/appengine-java-sample
Compile the simple-jetty-main
cd appengine-java-sample/simple-jetty-main mvn install
If this fails with an error about the Java target version, make sure you've switched to the Open JDK 11 as described above.
Change to the
<PROJECT_ID> below with your project ID:
mvn package appengine:deploy -Dapp.deploy.projectId=<PROJECT_ID>
/spanner: will run a number of sample operations against the Spanner instance.
Individual tasks can be run using the
task query parameter.
for the supported set of tasks.
To execute the endpoint handler of the deployed sample application, open
https://<PROJECT_ID>.appspot.com/spanner in a web browser.
Note: by default all the Spanner example operations run in order, so this endpoint handler may take a while to return.