Bookshelf app for Java

The Bookshelf app is a sample web app written in Java that shows how to use a variety of Google Cloud Platform (GCP) products, including:

  • App Engine flexible environment
  • Cloud SQL
  • Cloud Datastore
  • Cloud Storage
  • Compute Engine

This tutorial explores the Bookshelf app and discusses how each feature of the app is implemented using familiar technologies and services provided by GCP.

The Bookshelf app is based on the javax.servlet web application framework and uses JavaServer Pages. The Bookshelf sample app uses Servlets. However, the concepts and technologies explored are applicable regardless of which framework you use. You could implement this app in another web application framework of your choice, for example, Spring Boot (sample).

Screen shot of the Bookshelf app showing controls and book covers

The Bookshelf sample app stores a collection of book titles. Anyone who has access to the app can add books to the list. The sample app offers these features:

  • Users can view the list of books.
  • Users can add and remove books from the list.
  • Users can edit book details.
  • Users can upload cover images for books.
  • Users can log in with their Google Account and view the books that they have added to the list.


  • Clone or download the sample app.
  • Build the app and run it on your local machine.
  • Deploy the app to App Engine.
  • Walk through the sample code.
  • Learn how the app stores structured data.
  • Learn how the app stores binary data in Cloud Storage.
  • Learn how the app authenticates users.
  • Learn how the app creates event logs that are visible in the Google Cloud Platform Console.


This tutorial uses billable components of GCP, including Compute Engine.

This tutorial has several steps, and each step is documented on its own page. The final page of the tutorial includes instructions for cleaning up resources so you won't continue to be billed for GCP services. If you decide not to complete all the steps of the tutorial, see the cleanup instructions on the final page.

Before you begin

  1. Use the GCP Console to set up your Google Cloud Platform project:
    1. Create a new GCP project, create an App Engine app, and then enable billing in that project.
      Go to App Engine

      When prompted, select the region where you want your App Engine app located, and then enable billing. After your GCP project is created, the Dashboard opens.

    2. Enable the Cloud Datastore, Cloud Pub/Sub, Cloud Storage JSON, Stackdriver Logging, and Google+ APIs.

      Enable the APIs

  2. To deploy a Java app to App Engine, you must first set up your environment. See Using Apache Maven and the App Engine Plugin for details.
  3. Download, install, and initialize the Cloud SDK.
    Download the Cloud SDK
  4. Acquire local credentials for authenticating with GCP services.
    gcloud auth application-default login
  5. Verify that your default project is correct.
    gcloud config list
    If the project ID listed in the output isn't the project that you intended to use for this tutorial, set the project.
    gcloud config set project [YOUR_PROJECT_ID]
    where [YOUR_PROJECT_ID] is the ID of the project that you created or chose to use for this tutorial.
  6. Clone the sample repository.

    git clone

    Alternatively, you can download the sample as a zip file and extract it.

This tutorial assumes that you are familiar with Java and that you have Java 8 and Maven installed.

Tutorial structure

The Bookshelf tutorial has several parts that demonstrate how the sample app uses various GCP services.

The forms part of the tutorial demonstrates how the app uses web forms to to receive and store book information.

The structured data part of the tutorial demonstrates how the sample app stores book information in a SQL or NoSQL database.

The app's web page displays a form where the user can enter the title, author, description, and publication date of a book. For each book entered, the app stores this information in a database, so it can be retrieved later for viewing or editing. For this step of the tutorial, you have your choice of two databases: Cloud Datastore or Cloud SQL. After you complete this step with one of the databases, you can move on to the next step.

The Cloud Storage part of the tutorial demonstrates how the sample app stores binary data in Cloud Storage. On the app's web page, the user can specify a cover image for each book. The app stores the cover images in a Cloud Storage bucket.

The authorization part of the tutorial demonstrates how the app provides a sign-in flow for the user. When a user is signed in, any books entered are associated with the individual user. Signed-in users see both books created by anonymous users and their own books. Other users cannot see books created by a signed-in user.

The logging part of the tutorial demonstrates how the app writes logs that become visible in the Google Cloud Platform Console. Logs of this type can provide diagnostic information during app development.

Was this page helpful? Let us know how we did:

Send feedback about...