April 1, 2010

Spring 3 + maven2 + Google App Engine: Part 1 [Initial Project Setup]

Recently a co-worker started down the path of Spring 3, Spring MVC and Google App Engine. After hearing him talk about it, I decided it was time for me to figure out what the hype was and figure out how to program something using the "cloud".

This series of post will discuss one approach to getting my favorite Java web-app stack of Spring 3, Spring MVC (both with annotations), maven2 and all developed on Google App Engine.  Since unit testing is a corner stone of Agile development, JUnit test will also be included to show how to test your code prior to deployment to GAE servers.

This series assumes that you have and know how to use the following: Google login (Gmail or iGoogle for example), Java 1.6, some IDE (Eclipse, NetBeans, InteliJ, Notepad++, etc) though you do not need to install the suggested "Plugins", maven2, Ant 1.7+, web browser, command line

We will be building a simple "Movie Listing" web application where you can enter a movie, add a comment (single user, for now), add "Actors" to that movie. The model and idea is very simple and easy to define so we can focus on the technology.

Step 1: Sign up for a Google App Engine
First off, you will need to sign up for a Google App Engine account before you can do anything else.  Visit http://code.google.com/appengine/ and click on "Sign Up" under "Getting Started" on the right side navigation.

Note: Remember the URL you fill out as the name of your application, this will be used later in the POM file

Step 2: Setup the project
Once you have your GAE account setup, you need to setup your web application. 

Suggested directory structure and project layout:
    - main
        - resources
        - site
            - img
            - javascript
            - css
        - webapp
            - WEB-INF
        - java
            - com
                - example
                    - controllers
    - test
        - resources
        - java
            - com
                - example
                    - controllers

This is just a standard Spring Web App, nothing special here.  As a shortcut, you can use the maven command: (this will create most of the folder structure and default files)

mvn archetype:create -DgroupId=com.example.app -DartifactId=movie-app -DarchetypeArtifactId=maven-archetype-webapp

At this point, you should be able to "clean" and "install" the application.  Nothing will happen since we have not setup the project, which is in the next post.

Run the project with:

mvn clean install

Depending on how your maven usage, different plugins may need to download but ultimately you should see "Build Successful" in the output.

No comments: