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 :
- JDK 1.6
- Eclipse 3.7 + Google Plugin for Eclipse
- Google App Engine Java SDK 1.6.3.1
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
Figure – Deselect the “Google Web ToolKit“, and link your GAE Java SDK via the “configure SDK” link.
Click finished, Google Plugin for Eclipse will generate a sample project automatically.
3. Hello World
Review the generated 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
and also the hello world servlet – http://localhost:8888/helloworld
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.
Figure 1.2 – Sign in with your Google account and click on the Deploy button.
Figure 1.3 – If everything is fine, the hello world web application will be deployed to this URL – http://mkyong123.appspot.com/
Done.
Please create artical to deploy existing Maven Project on Google cloud
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
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
It was error because of JDK compliance changed JDK compliance to JDK 7 ,It is working fine now.
Thanks MKyong. you helped me a lot, thanks again
how to creatw application id on google app engine please give steps
This is F****** fkyong article…. remove it.
hold ur tongue
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?
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?
Posted on wrong article – please ignore…..
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”
Thank for this article.
This article used as my initiate step.
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.
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
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
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
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.
hi mkyong thanks for this.
all working is fine.
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.
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\
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\
How do i make a JSP as the welcome page,i tried changing in web.xml but found no use 🙁
any help please??
hi mkyong thanks for this and all post
can you describe why we will use Google app engine?
Why GAE, read this – https://developers.google.com/appengine/whyappengine.
But, make sure you know all those GAE limitation, i saw many apps failed or move away from GAE because they have to follow and deal with the GAE rules. Read this article – 13 Reasons Why One Developer Dropped Google App Engine
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
Thank you mkyong ! works like a charm