If you are migrating to the latest supported Java version and your app does not use legacy bundled services, you must re-package your App Engine Java 8 web application into an executable JAR file.
Your application must have a Main
class that starts a web server that responds
to HTTP requests on port 8080, which might be specified by the PORT
environment
variable.
For example:
WAR migration example (Java 11)
The following instructions demonstrate how to repackage an App Engine
Java 8 hello-world
application as a JAR to run on the Java 11 runtime.
The migration uses the appengine-simple-jetty-main
artifact. This provides a
Main
class with a simple Jetty web server that loads a WAR file and packages
your app into an executable JAR file:
Clone the Embedded Jetty Server artifact to your local machine:
git clone https://github.com/GoogleCloudPlatform/java-docs-samples
Alternatively, you can download the sample as a zip file and extract it.
Change to the directory that contains the sample code:
cd java-docs-samples/appengine-java11/appengine-simple-jetty-main/
Install the dependency locally:
mvn install
Add the following code to your project
pom.xml
file:appengine-simple-jetty-main
dependency:maven-dependency
plugin: App Engine deploys files located in the${build.directory}/appengine-staging
directory. By adding themaven-dependency
plugin to your build, App Engine installs your specified dependencies to the correct folder.
Create an
entrypoint
element in yourapp.yaml
file to call theappengine-simple-jetty-main
object and pass your WAR file as an argument. For example, see thehelloworld-servlet
sampleapp.yaml
file:To run your application locally:
Package your application:
mvn clean package
Start the server with your WAR file as an argument.
For example, you can start the server in the
helloworld-servlet
sample by running the following command from yourjava-docs-samples/appengine-java11/appengine-simple-jetty-main/
folder:mvn exec:java -Dexec.args="../helloworld-java8/target/helloworld.war"
In your web browser, enter the following address:
To deploy your application:
gcloud tooling
gcloud app deploy
Maven plugin
mvn package appengine:deploy -Dapp.deploy.projectId=PROJECT_ID
Replace PROJECT_ID with the ID of your Google Cloud project. If your
pom.xml
file already specifies your project ID , you don't need to include the-Dapp.deploy.projectId
property in the command you run.