This document describes how to repackage a Java 8 application as a
JAR
file to run on the Java 11/17 runtimes.
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
The following instructions demonstrate how to repackage an App Engine
Java 8 hello-world
application as a JAR to run on the Java 11/17 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 the
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. TheWAR
version must be same as the version listed in yourpom.xml
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-war
sample by running the following command from yourjava-docs-samples/appengine-java11/appengine-simple-jetty-main/
folder:mvn exec:java -Dexec.args="../flexible/java-11/helloworld-war/target/helloworld-1.war"
In your web browser, enter the following address:
To deploy your application using 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.