The Java 8 / Jetty 9 runtime uses Open JDK 8 and Jetty9 with Servlet 3.1.
Before you start developing, follow these steps:
- Download the Google Cloud SDK
Organizing your files
Your development file hierarchy should look like this:
MyDir/ [pom.xml] [build.gradle] [index.yaml] [cron.yaml] [dispatch.yaml] src/main/ appengine/ app.yaml docker/ [Dockerfile] java/ com.example.mycode/ MyCode.java webapp/ [index.html] [jsp.jsp] WEB-INF/ [web.xml]
You'll need to define an
app.yaml file that looks like this:
runtime: java env: flex handlers: - url: /.* script: this field is required, but ignored
app.yaml settings are described in
The additional configuration files
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
web.xml is optional and is needed only if you are not using Servlet 3.x annotations.
You can place static web content in your
webapp/ directory as well as
Jetty 9 which App Engine
flexible environment uses as its Servlet container uses
as the default JSP implementation and includes JSTL taglibs.
The Dockerfile file is optional and is used if you want to customize the Java runtime.
The Java 8/Jetty 9 runtime is aware of these environment variables, all are optional:
- JAVA_OPTS Optional extra java command options
- DBG_ENABLE Used to run the jdpa debugger locally, and Stackdriver Debugger for deployed apps
- DBG_PORT Used for local debugging on an image
env_variables key in the
app.yaml file to set environment variables:
env_variables: DBG_ENABLE: true # OPTIONAL
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 PubSub, and
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
Add these lines in your maven
pom.xml file to add the
Jetty 9 Maven Plugin:
<plugin> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>9.4.2.v20170220</version> </plugin>
To run your app locally, use the Maven command:
Deploying your app
If you need to initialize the Google Cloud SDK, do so with the command:
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
Customizing the Java 8 / Jetty 9 runtime
You don't need a Dockerfile to deploy your app into the Java 8/Jetty 9 runtime.
If your app requires additional configuration, you can explicitly provide a
Dockerfile to customize the Java runtime. The Dockerfile must include the base
gcr.io/google-appengine/jetty. You can add additional directives to the
Dockerfile to customize the Java runtime. See
Building Custom Runtimes.
Your Dockerfile should begin like this:
FROM gcr.io/google-appengine/jetty ADD test-webapp-1.0-SNAPSHOT.war $JETTY_BASE/webapps/root.war WORKDIR $JETTY_BASE RUN java -jar $JETTY_HOME/start.jar --approve-all-licenses --add-to-startd=jmx,stats,hawtio \ && chown -R jetty:jetty $JETTY_BASE
In this case,
test-webapp-1.0-SNAPSHOT.war is the name of the built WAR file in your
target/ directory (maven), or