Saturday, March 3, 2012

Get your app online in 10 minutes with Google App Engine!

In this post I'll explain how to easily get an app online and running in under 10 minutes. There are a few thing we need before we can start, though:
The Google App Engine SDK can easily be installed from within STS itself.

So, once we have all these prerequisited, we can get started! First thing you have to do is tell Google you want to deploy a new application. To do this, go to the Google App Engine start page, and create an application.

I named my app blogtryouts.

Now we are ready to actually build an application. Springsource Toolsuite comes with Maven preconfigured, so we might as well use Maven and its rich collection of archetypes to get going. So, in STS, create a new Maven project (File -> New -> Other..., and then select Maven project)

A wizard starts to help you create a new Maven project. Make sure you leave the Create a simple project (skip archetype selection) UNCHECKED! We're going to select a Maven archetype to get started really fast. More information about Maven Archetypes can be found here. When you click next, you can select the maven archetype you want to use. Filter on gae, and select the archetype using the framework you desire. I chose Wicket, cause I like the way it works (and how you can have a web designer do the tedious HTML/CSS styling while you can focus on the real Java development). To use wicket, select gae-archetype-wicket.

Click Next. Now comes the screen where you enter your application information. Enter data concerning to your application in Group IdArtifact Id and package. In the gaeApplicationName field, you enter the name of the application you created on appengine.google.com. In our case, this was blogtryouts.

Also notice the gaeApplicationVersion field. It defaults to test. We'll change it to release, to deploy a release version of our app. Click Finish. Maven will now create an archetype!

Now, there are still some issues before you can deploy your application. You have to put the Google App Engine SDK to your buildpath. I have no idea why this isn't done by default, but it isn't, so we'll have to do it ourselves. Easiest way is by right clicking your project, and select Google -> App Engine Settings... Basically, you can just hit Ok, to accept all default values.

Now that the SDK has been added, there still is 1 problem to be addressed. I think it's a bug in either STS or the Maven Archetype, but the appengine-local-runtime artifact seems to be missing. You can just go to the pom, and delete the entry.

<dependency>
  <groupId>com.google.appengine</groupId>
  <artifactId>appengine-local-runtime</artifactId>
  <version>${gae.version}</version>
  <scope>test</scope>
</dependency>


Now, build the project by using the maven package command. The necessary files and folders will be created, and your application is ready to be deployed! When Maven has finished packaging, right click your application in STS, select Google -> Deploy to App Engine... and deployment will start. When it's finished, your application is available at yourAppname.appspot.com.

If you used test instead of release in the gaeApplicationVersion I mentioned earlier, it would deploy to test.yourAppname.appspot.com.

Good luck and have fun!


No comments:

Post a Comment