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 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 21)
The following instructions demonstrate how to repackage an App Engine
hello-world WAR application as a JAR to run on the Java 21 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-samplesAlternatively, 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/flexible/repacking-legacy-applications/appengine-simple-jetty-main/Build the Jetty runner JAR:
mvn installThis generates
jetty-jar-with-dependencies.jarin yourtarget/directory.Configure the
pom.xmlbuild file for the Jetty server:- Compiler properties (Java 21):
- Embedded Jetty dependencies:
maven-assembly-pluginconfiguration:
Place the generated
jetty-jar-with-dependencies.jarand your application WAR file. For example,helloworld.warin the same directory.Create an
app.yamlfile in your application directory to specify the Java 21 runtime and anentrypointelement to call thejetty-jar-with-dependencies.jarfile and pass your WAR file as an argument:runtime: java21 entrypoint: 'java -jar jetty-jar-with-dependencies.jar helloworld.war'To run your application locally:
Start the server with your WAR file as an argument:
java -jar jetty-jar-with-dependencies.jar helloworld.warIn 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.xmlfile already specifies your project ID , you don't need to include the-Dapp.deploy.projectIdproperty in the command you run.