Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Jika bermigrasi ke versi Java terbaru yang didukung dan
aplikasi Anda tidak menggunakan
layanan paket lama, Anda harus memaketkan ulang aplikasi web Java 8
App Engine Anda menjadi file JAR yang dapat dieksekusi.
Aplikasi Anda harus memiliki class Main yang memulai server web yang merespons
permintaan HTTP di port 8080, yang mungkin ditentukan oleh variabel lingkungan PORT.
Contoh:
importcom.sun.net.httpserver.HttpServer;importjava.io.IOException;importjava.io.OutputStream;importjava.net.InetSocketAddress;publicclassMain{publicstaticvoidmain(String[]args)throwsIOException{// Create an instance of HttpServer bound to port defined by the // PORT environment variable when present, otherwise on 8080.intport=Integer.parseInt(System.getenv().getOrDefault("PORT","8080"));HttpServerserver=HttpServer.create(newInetSocketAddress(port),0);// Set root URI path.server.createContext("/",(vart)->{byte[]response="Hello World from Google App Engine Java 11.".getBytes();t.sendResponseHeaders(200,response.length);try(OutputStreamos=t.getResponseBody()){os.write(response);}});// Start the server.server.start();}}
Contoh migrasi WAR (Java 11)
Petunjuk berikut menunjukkan cara memaketkan ulang aplikasi hello-world Java 8
App Engine sebagai JAR untuk dijalankan di runtime Java 11.
Migrasi menggunakan artefak appengine-simple-jetty-main. Tindakan ini akan menyediakan
class Main dengan server web Jetty sederhana yang memuat file WAR dan memaketkan
aplikasi Anda ke dalam file JAR yang dapat dieksekusi:
Clone artefak Jetty Server Tersemat ke komputer lokal Anda:
App Engine men-deploy file yang berada di
direktori ${build.directory}/appengine-staging. Dengan menambahkan
plugin maven-dependency ke build Anda, App Engine akan menginstal
dependensi yang Anda tentukan ke folder yang benar.
Buat elemen entrypoint dalam file app.yaml untuk memanggil
objek appengine-simple-jetty-main dan meneruskan file WAR sebagai
argumen. Misalnya, lihat contoh helloworld-servlet
file app.yaml:
Mulai server dengan file WAR Anda sebagai argumen.
Misalnya, Anda dapat memulai server dalam
contoh helloworld-servlet
dengan menjalankan perintah berikut dari
folder
java-docs-samples/appengine-java11/appengine-simple-jetty-main/ Anda:
Ganti PROJECT_ID dengan ID Google Cloud project Anda. Jika
file pom.xml sudah
menentukan
project ID
, Anda tidak perlu menyertakan properti -Dapp.deploy.projectId dalam
perintah yang dijalankan.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-19 UTC."],[[["\u003cp\u003eMigrating to the latest supported Java version requires repackaging App Engine Java 8 web applications into executable JAR files if they don't utilize legacy bundled services.\u003c/p\u003e\n"],["\u003cp\u003eThe application's \u003ccode\u003eMain\u003c/code\u003e class must initialize a web server to handle HTTP requests on port 8080, potentially configured via the \u003ccode\u003ePORT\u003c/code\u003e environment variable.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eappengine-simple-jetty-main\u003c/code\u003e artifact offers a \u003ccode\u003eMain\u003c/code\u003e class with a basic Jetty server to load WAR files, facilitating the creation of an executable JAR.\u003c/p\u003e\n"],["\u003cp\u003eTo correctly install the dependencies, you must add the \u003ccode\u003emaven-dependency\u003c/code\u003e plugin in your project's \u003ccode\u003epom.xml\u003c/code\u003e file and make sure that the files are installed to the \u003ccode\u003e${build.directory}/appengine-staging\u003c/code\u003e directory.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eapp.yaml\u003c/code\u003e file needs an \u003ccode\u003eentrypoint\u003c/code\u003e that references the \u003ccode\u003eappengine-simple-jetty-main\u003c/code\u003e object and provides your WAR file as an argument, as well as to correctly deploy, \u003ccode\u003egcloud app deploy\u003c/code\u003e or \u003ccode\u003emvn package appengine:deploy -Dapp.deploy.projectId=PROJECT_ID\u003c/code\u003e can be used.\u003c/p\u003e\n"]]],[],null,[]]