The Google App Engine (GAE) is a wonderful playground for your apps, especially when you have no server at hand. It gives you everything you need for free, up to a certain limit. As I happened to be a Java developer it became really interesting when the GAE started supporting Java. You have to register for a GAE account and then apply for Java to be activated. There is a small waiting time but there still seem to be open slots.
As I’m working with Apache Wicket at the moment I thought it would be a nice idea to give you everything you need to get started with development with the GAE and Wicket as your frontend. So in the following lines we will set up a minimal Java / Wicket application and deploy it into the GAE.
Download and install the Google App Engine Java
You’ll find everything you need to know on Google’s page: http://code.google.com/appengine/
Make sure to select the Java SDK and not the Python one. While downloading you can register and get a GAE account. After you are locked in apply for the Java environment. The developer kit brings along an application server, so that you can test your application locally. It might take some time till you get the confirmation link which will be telling that you’re free to use Java. Until then you have to limit your experiments to your local machine.
Creating the Wicket Project with Maven
As build tool we will be using Maven, so if you’re new to that you might want to read the Maven tutorial of my colleague Phillip. It gives a good introduction of maven and how it will aid you in software development.
For the impatient, here’s the quickstart, as found on the Wicket homepage:
mvn archetype:create -DarchetypeGroupId=org.apache.wicket \ -DarchetypeArtifactId=wicket-archetype-quickstart \ -DarchetypeVersion=1.4-rc2 \ -DgroupId=com.united-coders -DartifactId=gae-minimal
I’ll be using the second release candidate of Wicket 1.4. Running the command will leave you with the project structure we’ll be working with. You can run and deploy this in you local servlet containter, but to deploy it into the GAE we need to make some changes.
Google App Engine specific changes
As mentioned on Alastair Maw’s blog, we need to make a few changes to the project so that it will be running, once deployed. This is due to the special environment (the sandbox) the application will be running in. For our example we have to change the application so that it does not spawn any extra threads. Alastair Maw already mentioned what we have to do, so we take his advice and then import the GAE settings into our project, so that we can deploy it.
Changes in the Wicket project
When building the project for deployment make sure to enable the deployment mode. In deployment mode Wicket does not try to spawn any processes for monitoring changes in resource files. This can be done in the configuration file or in the command line when building the project. Because this is a setting only used before deployment I prefer to use the command line option and leave the configuration untouched.
So when you’re ready to deploy use the following command: (not yet, we need to make some more changes. but it should compile)
mvn -Dwicket.configuration=deployment clean package
Additionally we need to override the creation of the newSessionStore(), so that it does not run in a separate thread in the background.
So edit your WicketApplication.java as shown below.
public class WicketApplication extends WebApplication { /** * Constructor */ public WicketApplication() { } /** * @see org.apache.wicket.Application#getHomePage() */ public Class<HomePage> getHomePage() { return HomePage.class; } @Override public HttpSessionStore newSessionStore(){ return new HttpSessionStore(this); } }
GAE specific settings
Take the appengine-web.xml file from the new_project_template in the demo folder and copy it to your projects src/main/webapp/WEB-INF/ folder.
Enable session support and enter the name of your project (as shown in the GAE). After that your appengine-web.xml file should look similar to this:
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0"> <!-- Replace this with your application id from http://appengine.google.com --> <application>nameOfYourProject</application> <version>1</version> <sessions-enabled>true</sessions-enabled> </appengine-web-app>
Deploy your application into the Google App Engine
After building your project with maven you can upload the project files with the script supplied with the SDK.
./bin/appcfg.sh update projects/wickethelloworld/target/wickethelloworld-1.0-SNAPSHOT
That’s it. Sources are attached. The deployed app can be found here: http://wickethelloworld.appspot.com/
UPDATE
* The limit of available accounts has been abolished.
And there two articles I’d recommend reading when you want to get a bit more detail before you start:
* Google App Engine for Java – 3 Tips for Getting Started
* Google App Engine For Java – Microblogging Case Study

Nico Heid

Latest posts by Nico Heid (see all)
- Raspberry Pi Supply Switch, start and shut down your Pi like your PC - August 24, 2015
- Infinite House of Pancakes – code jam 2015 - July 13, 2015
- google code jam 2014 – magic trick - April 18, 2014