The Java 8 Runtime

The Java 8 runtime does not include any web-serving framework. The only requirement is that your app should listen and respond on port 8080. The sample code here shows how you can add your own framework, such as SparkJava or Spring Boot, to the Java 8 runtime.


Before you start developing, follow these steps:

Adding the App Engine Maven plugin

To deploy using maven, you will need to add the appengine-maven-plugin to your pom.xml:


Other options for deploying include using the gcloud app deploy command or the App Engine Gradle plugin.

The Maven assembly plugin

Most apps will require adding the Maven assembly plugin to their pom.xml which creates a jar with dependencies. You may also create a Fat Jar.


Note that you need to identify the main class to the plugin, in this case

Organizing your files

Your development file hierarchy should look like this:


Required files


You'll need to define an app.yaml file that looks like this:

runtime: custom
env: flex

Other app.yaml settings are described in Using app.yaml.

JAR file

You must create a JAR file for your app. Since this runtime contains only Open JDK 8, you must install your own web serving framework, such as Spring Boot or Spark. Your app will listen to HTTP port 8080.


You will also need to add a Dockerfile to src/main/docker/. The file must include the base image This example project shows how to use the ADD directive to add your build jar as app.jar, and the CMD directive to set the arguments for the java command.

ADD spark-1.0-jar-with-dependencies.jar app.jar
CMD [ "java","","-jar","/app.jar"]

Optional files

The additional configuration files index.yaml, cron.yaml, and dispatch.yaml are optional. They are placed at the top level of MyDir. If you use any these files they must be deployed separately with the gcloud app deploy command.

Environment variables

Use the env_variables key in the app.yaml file to set environment variables:

   MY_VAR_COLOR: 'blue'

Local Testing

You can build your app using:

mvn package

And run it using the java command line:

java -jar target/myjar.jar

Or, you can add the Maven Exec plugin to your pom.xml.


Note that you need to give both the main class (in this case and the path to the jar (in this case target/sparkdemo-1.0-jar-with-dependencies.jar). Then execute using the Maven command:

mvn exec:java

When you are testing in your local environment, you might prefer to use emulated Google cloud services, rather than remote Google cloud services. There are emulators for Cloud Datastore, Cloud PubSub, and Cloud Bigtable. Use the gcloud command to start them before you run your app:

gcloud beta emulators datastore start
gcloud beta emulators pubsub start
gcloud beta emulators bigtable start

Deploying your app

Use Maven to deploy your app:

mvn appengine:deploy

Alternatively, you can deploy either a Fat jar or war file, by placing them in a directory with an app.yaml as described above.

gcloud app deploy

If you are using any of the optional configuration files (index.yaml, cron.yaml, and dispatch.yaml) be sure to deploy them separately with the gcloud command, for example:

gcloud app deploy cron.yaml

Customizing the Java 8 runtime

You don't need a Dockerfile to deploy your app into the Java 8 runtime. If your app requires additional configuration, you can explicitly provide a Dockerfile to customize the Java runtime. The Dockerfile must include the base image You can add additional directives to the Dockerfile to customize the Java runtime. See Building Custom Runtimes.

Monitor your resources on the go

Get the Google Cloud Console app to help you manage your projects.

Send feedback about...

App Engine flexible environment for Java docs