Application Development

App Engine Java 11 is GA—deploy a JAR, scale it, all fully managed

GCP_AppEngine.jpg

Attention, Java developers. If you want to build modern Java backends, use modern frameworks, or use the latest language features of Java 11, know that you can now deploy and scale your Java 11 apps in App Engine with ease. 

We’re happy to announce that the App Engine standard environment Java 11 runtime is now generally available, giving you the flexibility to run any Java 11 application, web framework, or service in a fully managed serverless environment. 

Modern, unrestricted, managed
With the App Engine standard environment Java 11 runtime, you are in control of what you want to use to develop your application. You can use your favorite framework, such as Spring Boot, Micronaut, Quarkus, Ktor, or Vert.x. In fact, you can use pretty much any Java application that serves web requests specified by the $PORT environment variable (typically 8080). You can also use any JVM language, be it Apache Groovy, Kotlin, Scala, etc.

With no additional work, you also get the benefits of the fully managed App Engine serverless platform. App Engine can transparently scale your application up to handle traffic spikes, and also scale it back down to zero when there’s no traffic. App Engine automatically updates your runtime environment with latest security patches to the operating system and the JDK, so you don't have to spend time provisioning or managing servers, load balancer, or even any infrastructure at all!

You also get traffic splitting, request tracing, monitoring, centralized logging, and production debugger capabilities out of the box.

In addition, if you can start your Java 11 application locally with java -jar app.jar, then you can run it on App Engine standard environment Java 11 runtime, with all the benefits of a managed serverless environment.

Finally, the App Engine standard environment Java 11 runtime comes with twice the amount of memory than the earlier Java 8 runtime, at no additional cost. Below is a table outlining the memory limit for each instance class.

memory limits.png

Getting started with a Spring Boot application
At beta, we showed you how to get started with a simple hello world example. Now, let’s take a look at how to start up a new Spring Boot application.

To start up a new Spring Boot application, all you need is a GCP project and the latest gcloud CLI installed locally. Then, follow these steps:

1. Create a new Spring Boot application from the Spring Boot Initilizr with the Web dependency and unzip the generated archive. Or, simply use this command line:

  $ curl https://start.spring.io/starter.zip \
    -d dependencies=web -d baseDir=demo -o demo.zip
$ unzip demo.zip
$ cd demo

2. Add a new REST Controller that returns "Hello App Engine!":

src/main/java/com/example/demo/HelloController.java

  package com.example.demo;

import org.springframework.web.bind.annotation.*;

@RestController
public class HelloController {
	@GetMapping("/")
	String hello() {
		return "Hello App Engine!";
	}
}

3. Build the application JAR:

  $ ./mvnw package

4. Deploy it using gcloud CLI:

  $ gcloud app deploy target/demo-0.0.1-SNAPSHOT.jar

Once the deployment is complete, browse over to https://[PROJECT-ID].appspot.com to test it out (or simply run gcloud app browse). Your application will use the default app.yaml configuration, on an F1 instance class.

To customize your runtime options, such as running with more memory and CPU power, configure an environment variable, or change a Java command line flag, or add an app.yaml file:

src/main/java/appengine/app.yaml

  runtime: java11
instance_class: F2
env_variables:
  SPRING_PROFILES_ACTIVE: "prod"
entrypoint: java -noverify -jar demo-0.0.1-SNAPSHOT.jar

Then, you can deploy an application using either a Maven or Gradle plugin:

  $ ./mvnw package \
  com.google.cloud.tools:appengine-maven-plugin:2.2.0:deploy \
  -Dapp.deploy.projectId=[PROJECT-ID] \
  -Dapp.deploy.version=1

Note: You can also configure the plugin directly into Maven's pom.xml, or in Gradle's build script.

Finally, you can also deploy a pre-built JAR with an app.yaml configuration using the gcloud CLI tool. First create an empty directory and place both the JAR file and app.yaml in that directory so the directory content looks like this:

  appengine-demo/
 |
 +-- demo-0.0.1-SNAPSHOT.jar
 |
 \-- app.yaml

Then, from that directory, simply run:

  $ gcloud app deploy

Try it out!
Read the App Engine Standard Java 11 runtime documentation to learn more. Try it with your favorite frameworks with samples in the GCP Java Samples Github Repository. If you have an existing App Engine Java 8 application, read the migration guide to move it to App Engine Java 11. Finally, don’t forget you can take advantage of the App Engine free tier while you experiment with our platform.


From the App Engine Java 11 team: Ludovic Champenois, Eamonn McManus, Ray Tsang, Guillaume Laforge, Averi Kitsch, Lawrence Latif, and Angela Funk.