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

27 comments on “Google app engine Java hello world example using Eclipse

  1. Please create artical to deploy existing Maven Project on Google cloud

    Reply
  2. 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

    Reply
  3. 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

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

      Reply
  4. Thanks MKyong. you helped me a lot, thanks again

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

    Reply
  6. 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?

    Reply
  7. 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?

    Reply
  8. 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”

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

    Reply
  10. 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 Set the directory where generated files are created.

    Reply
  11. 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

    Reply
  12. 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

    Reply
  13. 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

    Reply
  14. 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.

    Reply
  15. hi mkyong thanks for this.
    all working is fine.

    Reply
  16. 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.

    Reply
  17. 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\

    Reply
  18. 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\

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

    Reply
      1. Hi mykong, following your tutorial everything works for me (thanks so much) but…

        …I have a problem when I try to do a little modification in the source code (just for example trying to change the “hello world” message with an other string) then -going to reload the page http://localhost:8888/helloworld- I see that the server still continues to load the previous original version of the servlet, and not my modified one.

        I’ve tried also to clean the project, in Eclipse, by clicking on Project -> clean, but nothing happens… the server continues to let me show the first version of the servlet.

        How I can easily reload, each time, my actual modified version of my servlet?
        I see that, in the WAR directory, the file *.java and *.class present the actual corrections, but the browser seems to work caching always the very first call of the servlet.

        What can I do?

        Thanks so much,
        Giordano from Italy

        Reply

Leave a Comment

Your email address will not be published. Required fields are marked *