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 Spring Boot, to the Java 8 runtime.
Before you start developing, download the latest version of the Google Cloud CLI or update your gcloud CLI to the current version:
gcloud components update
To deploy using maven, you will need to add the App Engine Maven Plugin to your
<plugin> <groupId>com.google.cloud.tools</groupId> <artifactId>appengine-maven-plugin</artifactId> <version>2.4.4</version> </plugin>
Other options for deploying include using the
gcloud app deploycommand or the App Engine Gradle plugin.
Follow the instructions for your application framework to configure the build of an executable JAR. This executable JAR must run via
java -jar app.jar. For example, refer to the Spring Boot documentation.
Organizing your files
Your development file hierarchy should look like this:
MyDir/ pom.xml [index.yaml] [cron.yaml] [dispatch.yaml] src/main/ appengine/ app.yaml docker/ Dockerfile java/ com.example.mycode/ MyCode.java
app.yaml file is required. Define a file that looks like this:
runtime: java env: flex
runtime: java, the runtime image
gcr.io/google-appengine/openjdk:8 is automatically selected when you deploy a
To select a JDK version, use the
runtime: java env: flex runtime_config: jdk: openjdk8
You can find other
app.yaml settings in
These configuration files are optional:
Place these files at the top level of
MyDir. If you use any these files, you
must deploy them separately with the
gcloud app deploy command.
Default entry point
The entry point for the OpenJDK 8 image is
processes passed command line arguments to look for an executable alternative or
arguments to the default command (
If the first argument to the image is not an executable, the
is implicitly added. For example:
$ docker run openjdk -jar /usr/share/someapplication.jar
If the first argument to the image is an executable, such as
bash, it will
run that command.
For example, you could run a shell with:
> docker run -it --rm openjdk bash root@c7b35e88ff93:/#
env_variables key in the
app.yaml file to set environment variables.
env_variables: MY_VAR_COLOR: 'blue'
The following table lists the environment variables that you can use to enable, disable, or configure features.
||JVM tmpdir args||JVM args||
||Available memory||size||Set by Google App Engine or
||Memory for the heap||percent||80|
||JVM heap args||JVM args||
||JVM GC args||JVM args||
||JVM other args||JVM args|
||JVM args||JVM args||See below|
||Shutdown thread dump||boolean||
||Shutdown heap info||boolean||
If not explicitly set,
JAVA_OPTS is defaulted to
The command line executed is effectively (where $@ are the args passed into the docker entry point):
java $JAVA_OPTS "$@"
You can build your app using:
And run it using the
java command line:
java -jar target/myjar.jar
Or, follow the instructions for you application framework on how to run the app locally.
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
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
After completing the configurations, you can use the Google Cloud CLI to deploy
this directory containing the
app.yaml file and the JAR using:
gcloud app deploy app.yaml
If you are using any of the optional configuration files
dispatch.yaml) be sure to deploy them
separately with the
gcloud command. For example:
gcloud app deploy cron.yaml
Use Maven to deploy your app:
mvn package appengine:deploy -Dapp.deploy.projectId=PROJECT_ID
Replace PROJECT_ID with the ID of your Google Cloud project. If
pom.xml file already
project ID, you don't need to include the
-Dapp.deploy.projectId property in the
command you run.
Use Gradle to deploy your app:
Customizing the Java 8 runtime
You don't need a Dockerfile to deploy your app into the Java 8 runtime. But, if your app requires additional configuration, you can explicitly provide a Dockerfile to customize the Java runtime.
If you want to use the image as a base for a custom runtime, you can specify
runtime: custom in your
app.yaml file and then write the Dockerfile like
FROM gcr.io/google-appengine/openjdk:8 COPY your-application.jar $APP_DESTINATION
These lines add the JAR in the correct location for the Docker container.
You can add additional directives to the Dockerfile to customize the Java runtime. See Building Custom Runtimes.