Search
Tags
Archives
- April 2010
- January 2010
- November 2009
- January 2009
- May 2008
- February 2008
- November 2007
- October 2007
Syndication
How to use Google App Engine Java with Maven
We all want to use Google App Engine with Maven, but Google stopped deploying GAE/J releases to their Maven repository for some reason. This article explains how to use Maven with App Engine. It also explains how to setup a local Maven repository. These instructions assume you’re using Linux.
Step 1 – Setup a Maven Repository
You need a local Maven repository. If you already have one setup, skip this step.
I have a VPS running Apache, and here’s the steps I followed:
# create a new shell account to use to publish maven artifacts useradd maven # set a password for this account passwd maven cd /www/mydocroot mkdir maven chown maven maven
Step 2 – Register your repository with your local settings file
I’m assuming you’re on Linux here.
cd $HOME cd .m2 (you may have to mkdir ~/.m2 if it doesn't exist already) vi settings.xml
You need to add a <server> block for your repository. My settings.xml looks like this:
<settings>
<servers>
<server>
<id>bitmechanic</id>
<username>maven</username>
<password>yourpasswordhere</password>
<filePermissions>664</filePermissions>
<directoryPermissions>775</directoryPermissions>
<configuration></configuration>
</server>
</servers>
</settings>
We will use the value you put in <id> in a moment.
Step 3 – Download and unzip the App Engine zip
Change the URL to whatever version of App Engine you’re downloading.
cd /tmp wget http://googleappengine.googlecode.com/files/appengine-java-sdk-1.3.0.zip unzip appengine-java-sdk-1.3.0.zip
Step 4 – Create a bash script to import the relevant JARs to your repository
cd /tmp vi app_engine_to_mvn.sh
Paste this in and edit the 3 variables at the top as desired.
#!/bin/sh # EDIT THESE: # version of app engine: VERSION=1.3.0 # your repository id from settings.xml: REPOSITORY=bitmechanic # url for deployment. here's what an scp one looks like # path should be to the directory you made in step 1 above URL=scp://myhost.com/www/mysite.com/htdocs/maven # This should stay as is mvn deploy:deploy-file -DgroupId=com.google -DartifactId=appengine-tools -Dversion=$VERSION \ -Dpackaging=jar -Dfile=lib/appengine-tools-api.jar -Durl=$URL -DrepositoryId=$REPOSITORY mvn deploy:deploy-file -DgroupId=com.google -DartifactId=appengine-local-runtime-shared \ -Dversion=$VERSION -Dpackaging=jar -Dfile=lib/shared/appengine-local-runtime-shared.jar \ -Durl=$URL -DrepositoryId=$REPOSITORY mvn deploy:deploy-file -DgroupId=com.google -DartifactId=appengine-local-runtime \ -Dversion=$VERSION -Dpackaging=jar -Dfile=lib/impl/appengine-local-runtime.jar \ -Durl=$URL -DrepositoryId=$REPOSITORY mvn deploy:deploy-file -DgroupId=com.google -DartifactId=appengine-api-stubs -Dversion=$VERSION \ -Dpackaging=jar -Dfile=lib/impl/appengine-api-stubs.jar -Durl=$URL -DrepositoryId=$REPOSITORY mvn deploy:deploy-file -DgroupId=com.google -DartifactId=appengine-api-labs -Dversion=$VERSION \ -Dpackaging=jar -Dfile=lib/impl/appengine-api-labs.jar -Durl=$URL -DrepositoryId=$REPOSITORY mvn deploy:deploy-file -DgroupId=com.google -DartifactId=appengine-sdk-api -Dversion=$VERSION \ -Dpackaging=jar -Dfile=lib/impl/appengine-api.jar -Durl=$URL -DrepositoryId=$REPOSITORY
Step 5 – Run app_engine_to_mvn.sh
chmod 755 app_engine_to_mvn.sh cd appengine-java-sdk-1.3.0 ../app_engine_to_mvn.sh
This will run a bunch of maven commands to import 6 JARs to your local repository. Maven will report errors if something goes wrong.
Step 6 – Add dependencies to your pom.xml
I’ve found that there are 6 JAR files that are useful to add:
<dependency>
<groupId>com.google</groupId>
<artifactId>appengine-tools</artifactId>
<version>1.3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google</groupId>
<artifactId>appengine-local-runtime-shared</artifactId>
<version>1.3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google</groupId>
<artifactId>appengine-local-runtime</artifactId>
<version>1.3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google</groupId>
<artifactId>appengine-api-stubs</artifactId>
<version>1.3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google</groupId>
<artifactId>appengine-sdk-api</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>com.google</groupId>
<artifactId>appengine-api-labs</artifactId>
<version>1.3.0</version>
</dependency>
That’s it!!