Google App Engine Quickstart for Java
Before you begin
Before running this sample, you must:
Download and install the Java SE Development Kit (JDK):
Download Apache Maven version 3.3.9 or greater:
Install and configure Maven for your local development environment.
Download the Hello World app
We’ve created a simple Hello World app for Java so you can quickly get a feel for deploying an app to Google Cloud Platform. Follow these steps to download Hello World to your local machine.
Clone the Hello World sample app repository to your local machine:
git clone https://github.com/GoogleCloudPlatform/java-docs-samples.git
Go to the directory that contains the sample code:
cd java-docs-samples/appengine/helloworld
In the resulting helloworld
files you’ll find the src
directory for a package called com.example.appengine.helloworld
that implements a simple HTTPServlet
.
Alternatively, you can download the sample as a zip file and extract it.
Test the application
Test the application using the development web server, which is included with the App Engine SDK.
-
Run the following Maven command from within your
helloworld
directory, to compile your app and start the development web server:mvn appengine:devserver
The web server is now listening for requests on port 8080.
- Visit https://localhost:8080/ in your web browser to see the app in action.
For more information about running the development web server, see the Java Development Server reference.
Make a change
You can leave the web server running while you develop your application. When you make a change, use the mvn clean package
command to build and update your app.
- Try it now: Leave the web server running, then edit
HelloServlet.java
to changeHello, world
to something else. - Run
mvn clean package
, then reload https://localhost:8080/ to see the results.
Deploy your app
To deploy your app to App Engine, you will need to register a project to create your project ID, which will determine the URL for the app.
-
In the Cloud Platform Console, go to the Projects page and select or create a new project.
-
Note the project ID you created above, and enter it in src/main/webapp/WEB-INF/appengine-web.xml. You can also set the app version in this file.
-
Upload your application to Google App Engine by invoking the following command.
mvn appengine:update
-
Your app is now deployed and ready to serve traffic at https://<YOUR_PROJECT_ID>.appspot.com/.