Google app engine Java hello world example using Eclipse

In this tutorial, we will show you how to use Eclipse to create a Google App Engine (GAE) Java project (hello world example), run it locally, and deploy it to Google App Engine account.

Tools used :

  1. JDK 1.6
  2. Eclipse 3.7 + Google Plugin for Eclipse
  3. Google App Engine Java SDK 1.6.3.1
Note
GAE supports Java 1.5 and 1.6.

P.S Assume JDK1.6 and Eclipse 3.7 are installed.

1. Install Google Plugin for Eclipse

Read this guide – how to install Google Plugin for Eclipse. If you install the Google App Engine Java SDK together with “Google Plugin for Eclipse“, then go to step 2, Otherwise, get the Google App Engine Java SDK and extract it.

2. Create New Web Application Project

In Eclipse toolbar, click on the Google icon, and select “New Web Application Project…

Figure – New Web Application Project

Choose new web application project

Figure – Deselect the “Google Web ToolKit“, and link your GAE Java SDK via the “configure SDK” link.

create new web application project

Click finished, Google Plugin for Eclipse will generate a sample project automatically.

3. Hello World

Review the generated project directory.

gae project directory

Nothing special, a standard Java web project structure.


HelloWorld/
  src/
    ...Java source code...
    META-INF/
      ...other configuration...
  war/
    ...JSPs, images, data files...
    WEB-INF/
      ...app configuration...
      lib/
        ...JARs for libraries...
      classes/
        ...compiled classes...

The extra is this file “appengine-web.xml“, Google App Engine need this to run and deploy the application.

File : appengine-web.xml


<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
  <application></application>
  <version>1</version>

  <!-- Configure java.util.logging -->
  <system-properties>
    <property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
  </system-properties>

</appengine-web-app>

4. Run it local

Right click on the project and run as “Web Application“.

Eclipse console :


//...
INFO: The server is running at http://localhost:8888/
30 Mac 2012 11:13:01 PM com.google.appengine.tools.development.DevAppServerImpl start
INFO: The admin console is running at http://localhost:8888/_ah/admin

Access URL http://localhost:8888/, see output

gae hello world demo

and also the hello world servlet – http://localhost:8888/helloworld

gae hello world demo

5. Deploy to Google App Engine

Register an account on https://appengine.google.com/, and create an application ID for your web application.

In this demonstration, I created an application ID, named “mkyong123”, and put it in appengine-web.xml.

File : appengine-web.xml


<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
  <application>mkyong123</application>
  <version>1</version>

  <!-- Configure java.util.logging -->
  <system-properties>
    <property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
  </system-properties>

</appengine-web-app>

To deploy, see following steps:

Figure 1.1 – Click on GAE deploy button on the toolbar.

deploy to google app engine

Figure 1.2 – Sign in with your Google account and click on the Deploy button.

deploy to google app engine

Figure 1.3 – If everything is fine, the hello world web application will be deployed to this URL – http://mkyong123.appspot.com/

deploy to google app engine

Done.

References

  1. Google App Engine – Getting Started: Java
  2. Google app engine Python hello world example using Eclipse

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

Leave a Reply

avatar
newest oldest most voted
Chaitanya Dalvi
Guest
Chaitanya Dalvi

Please create artical to deploy existing Maven Project on Google cloud

Rupal kathiriya
Guest
Rupal kathiriya

Hi,

I cant get redirect page after login during deploying the project.
I have created one project in GAE like TestDemo and got the project key testdemo and given to my local project by app engine settings
but then i tried to deploy it , i couldnt get redirect page . getting blank page after login

satish
Guest
satish

Hi Mkyong,

I Got this error while deploying app-“java.lang.IllegalArgumentException: Class file is Java 8 but max supported is Java 7” ,it work fine on localhost,can you please help in this issue

abc
Guest
abc

It was error because of JDK compliance changed JDK compliance to JDK 7 ,It is working fine now.

Rajesh subramanium
Guest
Rajesh subramanium

Thank you mkyong ! works like a charm

Balvinder Singh
Guest
Balvinder Singh

Thanks MKyong. you helped me a lot, thanks again

Dipali
Guest
Dipali

how to creatw application id on google app engine please give steps

Krishan
Guest
Krishan

This is F****** fkyong article…. remove it.

shankar
Guest
shankar

hold ur tongue

amy
Guest
amy

We are trying to find information on how you can raise the quantity of remarks on my own weblog, how did you achieve accomplishing this?

Mark
Guest
Mark

I cannot run it on Eclipse Juno. PyDev Run Configurations does not show “Deploy to GAE” or “Run Local” under PyDev Google App Run. Is there an alternative way to launch in Eclipse 4.2?

Mark
Guest
Mark

Posted on wrong article – please ignore…..

Bowon
Guest
Bowon

Do you have any more detail for do the web. I can see only “how to start” don’t have more detail like “how to contact your web form with java or Go” , “How to use Database”

Sadun89
Guest
Sadun89

Thank for this article.
This article used as my initiate step.

sai
Guest
sai
Hi, Mkyong I have followed everything what you have done.But when i running the application the following errors a raised.How to resolve these errors. Any suggestion please…… Usage: [options] Options: –help, -h Show this help message and exit. –server=SERVER The server to use to determine the latest -s SERVER SDK version. –address=ADDRESS The address of the interface on the local machine -a ADDRESS to bind to (or 0.0.0.0 for all interfaces). –port=PORT The port number to bind to on the local machine. -p PORT –sdk_root=DIR Overrides where the SDK is located. –disable_update_check Disable the check for newer SDK versions. –generated_dir=DIR… Read more »
Gowtham Gutha
Guest
Gowtham Gutha

Unable to send request/receive response with servlets.

Can you give me an example of a servlet taking request and giving response. Like taking the name of the user in a text field and printing it on the next page using Servlets.
I could not do that on Google App Engine

Loi Tran
Guest
Loi Tran

Hi,
After ‘Run web application’.I run but I got : “Development Mode requires the Google Web Toolkit Developer Plugin”.I downloaded but still get that error.Sorry my English not good.

Thanks

Shivaji
Guest
Shivaji

Expecting a stackmap frame at branch target 59 in method h.w.o.HwServlet.sendResponse(Ljavax/servlet/http/HttpServletResponse;Ljava/lang/String;)V at offset 0

shiv kumar
Guest
shiv kumar

hi mkyong
can you please provide me a sample application which uses Google CloudSQL + GAE + GWT ?? I am new on Google Cloud SQL and need help on it.

Anil Vaishnav
Guest
Anil Vaishnav

hi mkyong thanks for this.
all working is fine.

trackback
Google App Engine + Spring 3 MVC REST example | Top roms

[…] Google App Engine + Java + Google Plugin for eclipse example […]

Kaviyanka
Guest
Kaviyanka

Hi,

Can you please tell me the App engine version supports JDK 1.5.

I am using JDK 1.5 and app engine 1.4.3. but it still through s method not found exception.
But it perfectly working in JDK 1.6.

pronoy
Guest
pronoy

i get this error.plz anyone help me plz
The selected App Engine SDK is not valid: Failed to initialize App Engine SDK at C:\Users\user\Downloads\eclipse-jee-indigo-SR2-win32\eclipse\plugins\com.google.appengine.eclipse.sdkbundle_1.6.6\appengine-java-sdk-1.6.6\

pronoy
Guest
pronoy

i get this error
The selected App Engine SDK is not valid: Failed to initialize App Engine SDK at C:\Users\user\Downloads\eclipse-jee-indigo-SR2-win32\eclipse\plugins\com.google.appengine.eclipse.sdkbundle_1.6.6\appengine-java-sdk-1.6.6\

trackback
Google App Engine Tutorial

[…] and “Google App Engine Java SDK 1.6.3.1“.1. Quick StartSay hello to Google App Engine.Google App Engine + Java hello world example using Eclipse GAE + Eclipse + Java hello world example.Google App Engine + Python hello world example using […]

venkatesh
Guest
venkatesh

How do i make a JSP as the welcome page,i tried changing in web.xml but found no use :(
any help please??

trackback
Google App Engine + Spring 3 MVC REST example

[…] example, modify it and integrate with Google App Engine, you may also interest to read this – GAE + Java + Eclipse example 1. New Web Application ProjectIn Eclipse, create a new Web Application project, named as […]

trackback
Google App Engine + Struts 1 example

[…] Engine + Struts 2 example.This example is going to merge Struts 1.x hello world example and this GAE + Java example.1. New Web Application ProjectIn Eclipse, create a new Web Application project, named as […]

trackback
Google App Engine + Struts 2 example

[…] SDK 1.6.3.1Struts 2.3.1.2 Note Before proceed on this tutorial, make sure you read this – GAE + Java example and Struts 2 hello world example.1. New Web Application ProjectIn Eclipse, create a new Web […]

ali akbar azizkhani
Guest
ali akbar azizkhani

hi mkyong thanks for this and all post
can you describe why we will use Google app engine?