This tutorial creates a tiny application that displays a short message.
Before getting started, be sure to Download Apache Maven version 3.1 or greater and then install it. When you use Maven as described in these instructions, the required App Engine SDK libraries for Java will be automatically downloaded into your project.
Creating a simple
Clone the contents of this GitHub project by running the following commands:
$ git clone https://github.com/GoogleCloudPlatform/java-docs-samples.git $ cd 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
This servlet responds to any request by sending a response containing the message
Understanding the configuration files
There are three config files to look at in addition to
helloworld app uses Maven, which means you must specify a Project Object
Model, or POM, which contains information about the project and
configuration details used by Maven to build the project.
You will also need to configure App Engine's behavior using
appengine-web.xml. You can use this file to specify a version for your
application. More importantly, you'll eventually need to enter the Project ID
for your Google Cloud Platform project before you upload this
application. But don't worry about that now.
Java web applications use a deployment descriptor file to determine how URLs
map to servlets, which URLs require authentication, and other information. This
file is named
web.xml, and resides in the app's WAR under the
web.xml is part of the servlet standard for web applications.
Testing the application
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 running, listening for requests on port 8080. Test the application by visiting the following URL in your web browser:
During development, if you start your app in the development web server in offline
mode using the command
mvn appengine:devserver_start, you can force the
development web server to reload your app by doing the following:
- With the development web server running (started using the command
mvn appengine:devserver_start), edit your code.
- Trigger a build. In Maven you can do this using the command
mvn install. The development server will update with the new build.
- View the results in your web browser.
- When you are finished iterating, shut down the development web server using
Try it now: start the development web server using the command
mvn appengine:devserver_start, edit
HelloServlet.java to change
Hello, world! to something else, then rebuild
the project using
mvn install. Reload
http://localhost:8080/ to see the changes.
Note that to shut down a web server started using
mvn appengine:devserver_start, you
must use the command
mvn appengine:devserver_stop. Using Control-C won't work.
Leave the web server running for the rest of this tutorial. If you need to stop it, you can restart it again by running the command above.
Uploading the application
- Sign in to App Engine using your Google account. If you do not have a Google account, you can create a Google account with an email address and password.
If you haven't already done so, create a project for your App Engine app as follows:
- Visit the Google Cloud Platform Console and click Create Project.
- Supply the desired project name in the New Project form. It doesn't have to match your app name, but using the same name as your app might make administration easier.
- Accept the generated project ID or supply your own ID. This project ID is used as the App Engine application ID. Note that this ID can only be used once: if you subsequently delete your project, you won't be able to re-use the ID in a new project.
Note the application ID (project ID) you created above, and enter it in
src/main/webapp/WEB-INF/appengine-web.xml. While you're in there, set the version to something that suits you.
Upload your finished application to Google App Engine by invoking the following command.
Your app is now deployed and ready for users!
You have completed this tutorial.
The full URL for your application is
Optionally, you can instead purchase and use a top-level domain name for your
app, or use one that you have already registered.
Expanding on Hello, World!
In the "Creating a Guestbook" tutorial, you expand this simple application to become a fully-fledged Guestbook application that lets authenticated Google accounts post messages to a public page.