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.
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 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.
For more information about running the development web server, see the Java Development Server reference.
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.
HelloServlet.java
to change Hello, world
to something else.mvn clean package
, then reload http://localhost:8080/ to see the
results.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 http://<YOUR_PROJECT_ID>.appspot.com/.