Building Google App Engine Java projects with Maven2

Ok, so I had a whole bunch of work to do today and I\’ve just thrown it out the window: Google has unleashed Java support for Google App Engine.

This is huge news. The implementation is solid (it does its best, within the restrictions of Google\’s architecture, to support standards and avoid architectural lock-in).

Let\’s cut to the chase: I spent this afternoon working out how to build App Engine Java projects with Maven 2 instead of Ant.

I do this for several reasons, the main one being that the CMS I\’m building uses Maven as a build system and I love it. A secondary reason is that Maven easily gives me the power to target OSGI, App Engine, and plain ol\’ Java Servlets with the one project.

So here we go. First, here\’s a script to install some of Google\’s more obscure libraries into your local Maven repository:

#!/bin/sh

#install Google App Engine dependencies into local maven repository

#copyright 2009 Gravity Rail Pty Ltd

export CURR=`pwd`
export SDK=`pwd`
export LIB="${SDK}/lib"
export VERS="1.2.0"

cd $LIB

mvn install:install-file -Dfile=${LIB}/appengine-tools-api.jar 
  -DgroupId=com.google 
  -DartifactId=appengine-tools 
  -Dversion=${VERS} 
  -Dpackaging=jar 
  -DgeneratePom=true

mvn install:install-file -Dfile=${LIB}/shared/appengine-local-runtime-shared.jar 
  -DgroupId=com.google 
  -DartifactId=appengine-tools 
  -Dversion=${VERS} 
  -Dpackaging=jar 
  -DgeneratePom=true

mvn install:install-file -Dfile=${LIB}/shared/geronimo-el_1.0_spec-1.0.1.jar 
  -DgroupId=org.apache.geronimo.specs 
  -DartifactId=geronimo-el_1.0_spec 
  -Dversion=1.0.1 
  -Dpackaging=jar 
  -DgeneratePom=true

mvn install:install-file -Dfile=${LIB}/shared/geronimo-jsp_2.1_spec-1.0.1.jar 
  -DgroupId=org.apache.geronimo.specs 
  -DartifactId=geronimo-jsp_2.1_spec 
  -Dversion=1.0.1 
  -Dpackaging=jar 
  -DgeneratePom=true

mvn install:install-file -Dfile=${LIB}/shared/geronimo-servlet_2.5_spec-1.2.jar 
  -DgroupId=org.apache.geronimo.specs 
  -DartifactId=geronimo-servlet_2.5_spec 
  -Dversion=1.2 
  -Dpackaging=jar 
  -DgeneratePom=true

mvn install:install-file -Dfile=${LIB}/user/orm/geronimo-jpa_3.0_spec-1.1.1.jar 
  -DgroupId=org.apache.geronimo.specs 
  -DartifactId=geronimo-jpa_3.0_spec 
  -Dversion=1.1.1 
  -Dpackaging=jar 
  -DgeneratePom=true

mvn install:install-file -Dfile=${LIB}/user/orm/geronimo-jta_1.1_spec-1.1.1.jar 
  -DgroupId=org.apache.geronimo.specs 
  -DartifactId=geronimo-jta_1.1_spec 
  -Dversion=1.1.1 
  -Dpackaging=jar 
  -DgeneratePom=true

mvn install:install-file -Dfile=${LIB}/user/orm/datanucleus-appengine-1.0.0.final.jar 
  -DgroupId=org.datanucleus 
  -DartifactId=datanucleus-appengine 
  -Dversion=1.0.0.final 
  -Dpackaging=jar 
  -DgeneratePom=true

cd $CURR

Next, let\’s modify the ant build.xml file in the root of our project slightly to take account of Maven\’s default project layout:


    

    

    
        
        
            
        
        
            
        
    

    
        
        
            
                
            
        
    

    
        
        
            
                
            
        
        
        
        
            

            
        
    

    
        
    

    
        
    

    
        
    

    
        
    

    
        
    

    
        
            
                
            
            
                
            
        
    



Finally, we put in our pom.xml file that calls ant for tasks like deployment (doesn\’t quite work yet):


    4.0.0
    com.transitplatform
    TransitAppEngine
    war
    Transit App Engine
    1.0-SNAPSHOT
    
        war/WEB-INF/classes
        
            
                src/main/resources
            
            
                src/main/java
                
                    **
                
                
                    **/*.java
                
            
        
        
            
                maven-compiler-plugin
                
                    1.6
                    1.6
                
            
            
                maven-antrun-plugin
                
                    
                        1
                        
                        compile
                        
                            
                                
                                
                            
                        
                        
                            run
                        
                    
                    
                        2
                        
                        deploy
                        
                            
                                
                                
                            
                        
                        
                            run
                        
                    
                
            
        

    


    
        
            org.apache.wicket
            wicket
            1.4-rc2
        
        
            org.apache.geronimo.specs
            geronimo-jsp_2.1_spec
            1.0.1
        
        
            org.apache.geronimo.specs
            geronimo-jpa_3.0_spec
            1.1.1
        
        
            org.apache.geronimo.specs
            geronimo-jpa_3.0_spec
            1.1.1
        
        
            ant
            ant
            1.6.5
        
        
            ant
            ant-launcher
            1.6.5
        
        
            commons-logging
            commons-logging
            1.1.1
        
        
            commons-el
            commons-el
            1.0
        
        
            org.datanucleus
            datanucleus-core
            1.1.0
            
                
                    javax.transaction
                    transaction-api
                
            
        
        
            org.datanucleus
            datanucleus-jpa
            1.1.0
        
        
            org.datanucleus
            datanucleus-appengine
            1.0.0.final
        
        
            tomcat
            jasper-compiler
            5.0.28
        
        
            tomcat
            jasper-runtime
            5.0.28
        
        
            javax.jdo
            jdo2-api
            2.3-SNAPSHOT
            
                
                    javax.transaction
                    transaction-api
                
            
        
        
            javax.transaction
            jta
            1.1
        
        
            org.slf4j
            jcl104-over-slf4j
            1.4.3
        
        
            org.slf4j
            slf4j-simple
            1.4.3
        
    


    
        
            datanucleus
            Datanucleus Repository
            http://www.datanucleus.org/downloads/maven2/
        
    

Hope you find this useful, and good luck! Also, let me know if you have any corrections, compliments, duffel-bags-full-of-cash, etc.

Download a sample project here:

mavenappengine

10 Replies to “Building Google App Engine Java projects with Maven2”

  1. Your POM formatting is bust, can you put in a pre tag or something?

    I’m a bit confused about what the output is. You aim is to use Maven layout for Java and resource sources, and Google layout for the war content? FWFIW I tried that and it works with the Eclipse tooling as well.

  2. Dan,
    Quick stuff on getting the maven structure set up, but your page doesn’t seem to be rendering right to follow the example. I’ve tried Firefox, IE, and Opera with no success!
    James

  3. Here is a batch file for windows to do the gae artifact local maven repo installing:

    set LIB=d:downloadsappengine-java-sdk-1.2.0lib
    set VERS=1.2.0

    call mvn install:install-file -Dfile=%LIB%/appengine-tools-api.jar -DgroupId=com.google -DartifactId=appengine-tools -Dversion=%VERS% -Dpackaging=jar -DgeneratePom=true
    call mvn install:install-file -Dfile=%LIB%/shared/appengine-local-runtime-shared.jar -DgroupId=com.google -DartifactId=appengine-tools -Dversion=%VERS% -Dpackaging=jar -DgeneratePom=true
    call mvn install:install-file -Dfile=%LIB%/shared/geronimo-el_1.0_spec-1.0.1.jar -DgroupId=org.apache.geronimo.specs -DartifactId=geronimo-el_1.0_spec -Dversion=1.0.1 -Dpackaging=jar -DgeneratePom=true
    call mvn install:install-file -Dfile=%LIB%/shared/geronimo-jsp_2.1_spec-1.0.1.jar -DgroupId=org.apache.geronimo.specs -DartifactId=geronimo-jsp_2.1_spec -Dversion=1.0.1 -Dpackaging=jar -DgeneratePom=true
    call mvn install:install-file -Dfile=%LIB%/shared/geronimo-servlet_2.5_spec-1.2.jar -DgroupId=org.apache.geronimo.specs -DartifactId=geronimo-servlet_2.5_spec -Dversion=1.2 -Dpackaging=jar -DgeneratePom=true
    call mvn install:install-file -Dfile=%LIB%/user/orm/geronimo-jpa_3.0_spec-1.1.1.jar -DgroupId=org.apache.geronimo.specs -DartifactId=geronimo-jpa_3.0_spec -Dversion=1.1.1 -Dpackaging=jar -DgeneratePom=true
    call mvn install:install-file -Dfile=%LIB%/user/orm/geronimo-jta_1.1_spec-1.1.1.jar -DgroupId=org.apache.geronimo.specs -DartifactId=geronimo-jta_1.1_spec -Dversion=1.1.1 -Dpackaging=jar -DgeneratePom=true
    call mvn install:install-file -Dfile=%LIB%/user/orm/datanucleus-appengine-1.0.0.final.jar -DgroupId=org.datanucleus -DartifactId=datanucleus-appengine -Dversion=1.0.0.final -Dpackaging=jar -DgeneratePom=true

  4. Here is a batch file for windows to do the gae artifact local maven repo installing:

    set LIB=d:downloadsappengine-java-sdk-1.2.0lib
    set VERS=1.2.0
    
    call mvn install:install-file -Dfile=%LIB%/appengine-tools-api.jar -DgroupId=com.google -DartifactId=appengine-tools -Dversion=%VERS% -Dpackaging=jar -DgeneratePom=true
    call mvn install:install-file -Dfile=%LIB%/shared/appengine-local-runtime-shared.jar -DgroupId=com.google -DartifactId=appengine-tools -Dversion=%VERS% -Dpackaging=jar -DgeneratePom=true
    call mvn install:install-file -Dfile=%LIB%/shared/geronimo-el_1.0_spec-1.0.1.jar -DgroupId=org.apache.geronimo.specs -DartifactId=geronimo-el_1.0_spec -Dversion=1.0.1 -Dpackaging=jar -DgeneratePom=true
    call mvn install:install-file -Dfile=%LIB%/shared/geronimo-jsp_2.1_spec-1.0.1.jar -DgroupId=org.apache.geronimo.specs -DartifactId=geronimo-jsp_2.1_spec -Dversion=1.0.1 -Dpackaging=jar -DgeneratePom=true
    call mvn install:install-file -Dfile=%LIB%/shared/geronimo-servlet_2.5_spec-1.2.jar -DgroupId=org.apache.geronimo.specs -DartifactId=geronimo-servlet_2.5_spec -Dversion=1.2 -Dpackaging=jar -DgeneratePom=true
    call mvn install:install-file -Dfile=%LIB%/user/orm/geronimo-jpa_3.0_spec-1.1.1.jar -DgroupId=org.apache.geronimo.specs -DartifactId=geronimo-jpa_3.0_spec -Dversion=1.1.1 -Dpackaging=jar -DgeneratePom=true
    call mvn install:install-file -Dfile=%LIB%/user/orm/geronimo-jta_1.1_spec-1.1.1.jar -DgroupId=org.apache.geronimo.specs -DartifactId=geronimo-jta_1.1_spec -Dversion=1.1.1 -Dpackaging=jar -DgeneratePom=true
    call mvn install:install-file -Dfile=%LIB%/user/orm/datanucleus-appengine-1.0.0.final.jar -DgroupId=org.datanucleus -DartifactId=datanucleus-appengine -Dversion=1.0.0.final -Dpackaging=jar -DgeneratePom=true