Writing Java Hello World for Google app engine

After hearing the buzz about java support in Google App Engine I decided to write a hello, world application and run it on Google App Engine.

Add Google plugin for Eclipse

The first step is to add the Google plugin in eclipse using Help menu > Software Updates… > Add site>. The site url is:

http://dl.google.com/eclipse/plugin/3.4

eclipse-plugin-install
Restart eclipse after adding the plugin.

Create new project in eclipse

Create a new Web Application Project using File > New > Web Application Project

eclipse-new-web-app-project

Specify your project name and package name. To keep the application simple, uncheck ‘use GWT’ and check ‘Use app engine’, then click ‘Finish’

eclipse-new-web-app-options

This generates a working web application. The project structure looks like this:

eclipse-new-app-generated-structure

Run your web application locally

Right click on your application and click on Run as… > Web Application.

eclipse-run-as-web-app

This launches your web application locally on port 8080. You can access your application by typing the URL:

http://localhost:8080/hellogoogleapp

…. and your app says “Hello, World”!!

app-local-deploy

Create a Google App Engine account

Before you can deploy you hello world application to google app engine, you need to create an account on google app engine.

http://appengine.google.com/

welcome-to-goog-app-engine

You can sign in with your existing google account.

When you try creating your first application you must verify Your Account by SMS. Simply enter your mobile phone number and type the code that you get in the SMS.

verify-sms

Select a unique application id in Google App Engine

Application id, like login name must be a unique name. You need to select a unique application id before proceeding. After selection the application id, http://<your application id>.appspot.com is reserved for your application.

choose-appspot-id

Configure your eclipse application to use this application id

Right click on your eclipse project > Google > App engine settings. Enter your application id. Alternatively you can directly modify your appengine-web.xml file to add your application id.

   <application>hellogoogapp</application>

eclipse-google-app-engine-setting

Deploy your app to App Engine

Right click on your project > Google > Deploy to app engine.

eclipse-goog-deploy-to-app-engine

You will be prompted for your user name and password. This is your google account information.

eclipse-deploy-popup-auth

The above step should deploy your application to Google app engine. At the time of writing this feature is available to only the first 10000 users. If you are not one of the first 10,000 you will get the following message on the console.

java.io.IOException: Error posting to URL: http://appengine.google.com/api/appversion/...
400 Bad Request
Invalid runtime specified.

Unable to upload app: Error posting to URL: http://appengine.google.com/api/appversion/...
400 Bad Request
Invalid runtime specified.

If you don’t have access to the java version yet, you can apply for permission here.

After applying you should receive an email from google, it may take upto 1 or 2 days to get the email. The email looks like this:
google-app-engine-java-permission-granted-email

Try deploying the application again now. This time the deployment should be successful. You should see the following output on the console:

Creating staging directory
Scanning for jsp files.
Scanning files on local disk.
Initiating update.
Cloning 1 static files.
Cloning 13 application files.
Uploading 5 files.
Uploaded 1 files.
Uploaded 2 files.
Uploaded 3 files.
Uploaded 4 files.
Uploaded 5 files.
Deploying new version.
Will check again in 1 seconds
Closing update: new version is ready to start serving.
Uploading index definitions.
Deployment completed successfully

Access your live application on google app engine

Login to google app engine. You should see you application on the application overview page.

google-app-engine-applications-overview

You should see version 1 of your newly deployed app. Click on this link. This link should be your http://<applicationid>.appspot.com, for example http://hellogoogapp.appspot.com/.

Your application page shows you a list of all available servlets.

gae-hello-app-engine

Go ahead and click on the hello world servlet.

…. And finally, your google app says “Hello, world”. Here is the link to the app that I created: http://hellogoogapp.appspot.com/hellogoogleapp

gae-hello-world


References

Related posts:

  1. Using Google Analytics Event API to track your website performance
  2. What is Google Wave: in plain simple English in 2 minutes
  3. Amazon adds SimpleDB Support in AWS Toolkit for Eclipse
  4. Google introduces Page Speed
  5. What is Google TV … in 2 minutes

15 comments to Writing Java Hello World for Google app engine

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Get Adobe Flash playerPlugin by wpburn.com wordpress themes