Running the Jersey Webapp on Google App Engine

       This entry describes how easy it is to get your Jersey web application running on Google App Engine.

For the illustration purpose lets see how we can deploy the simple Helloworld-Webapp Jersey sample on the Google App Engine.

Simple Steps:

  1. Download Google App Engine.
  2. Follow the installation instructions for installing the app engine on your machine. It isn't really too much work, just unzip the bundle, and add its bin directory to your path.
  3. Download the Jersey helloworld-webapp sample, if you do not already have it.
  4. Create an XML file named appengine-web.xml, under WEB-INF parallel to the deployment descriptor web.xml. Google App Engine requires this file in the webapp's WEB-INF directory, for it to be able to run the application.
  5. Copy the following content to the created appengine-web.xml file:
    <?xml version="1.0" encoding="utf-8"?>
    <appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
        <application></application>
        <version>1</version>
    </appengine-web-app>
    
  6. Package the application using: mvn clean package -Dmaven.test.skip=true
  7. Deploy the application on Google App Engine using the command: dev_appserver.sh target/helloworld-webapp
  8. You will see the message which says server is running at http://localhost:8080/.
  9. In a web browser enter http://localhost:8080/helloworld. You see the application running.
That's it. You got the Jersey application running on Google App Engine :)



Comments:

Note that while you can run a Jersey web app in the local dev environment, it will not run "completely" on the real Google App Engine environment due to security restrictions. Plans are underway to make Jersey more compliant with GAE (> version 1.0.3), but when I tried last week, the current snapshot (1.1.1) still had complications. There is a hack to make Jersey run on GAE (http://lqd.hybird.org/journal/?p=123), but not a complete solution.

Posted by Elliot Smith on May 27, 2009 at 08:35 AM PDT #

Thanks Elliot.

I realized only later that there's some problem when we deploy the app on GAE. It seems its because of the sandboxing which they are using.

At a recent conference, I spoke to a couple of the GAE engineers, and they said they are working on a solution for such problems. Lets see if they come up with a solution soon.

Posted by Naresh on June 07, 2009 at 04:01 PM PDT #

I really hope they (GAE engineers) come up with a solution soon... as Jersey seems to be the nicest Java REST framework.

Posted by JP Richardson on June 29, 2009 at 10:48 AM PDT #

Looks like its going to take some time before the solution comes from GAE.
However, someone has been successful in finding a hack for getting the Jersey apps running on GAE. Please refer http://lqd.hybird.org/journal/?p=123

Posted by Naresh on July 08, 2009 at 04:02 PM PDT #

Here's what I did to get Jersey 1.1.5-ea bits running on GAE under Maven.
This is good because it downloads the GAE SDK for you and stores it in your
local Maven repository.

1. Download this Maven pom.xml file:
http://maven-gae-plugin.googlecode.com/svn/example/jsp-persistence-app/pom.xml

You will need to modify the line:
<mappingIncludes>\*\*/jdo/\*.class</mappingIncludes>
to point to your JDO classes.

Also, if you're using JSP tags there's a hack to get that to work
by copying the Java tools.jar file to the GAE lib dir.
(~/.m2/repository/com/google/appengine/appengine-java-sdk/1.3.0/appengine-java-sdk-1.3.0/lib/shared/tools.jar)

See: http://groups.google.com/group/google-appengine-java/browse_thread/thread/175e70cc0c93ded9

2. Add in the Jersey dependency and repo info:

<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.1.5-ea-SNAPSHOT</version>
</dependency>

<repository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net Repository for Maven</name>
<url>http://download.java.net/maven/2/</url>
<layout>default</layout>
</repository>
<repository>
<id>maven-repository.dev.java.net</id>
<name>Java.net Maven 1 Repository (legacy)</name>
<url>http://download.java.net/maven/1</url>
<layout>legacy</layout>
</repository>

Here's the usage page for the maven-gae-plugin:
http://code.google.com/p/maven-gae-plugin/wiki/Usage

Basically 'mvn gae:run' to run it local and 'mvn gae:update' to load
it to the app engine. You will need the supporting GAE and JDO config files:
./src/main/webapp/WEB-INF/appengine-web.xml
./src/main/resources/META-INF/jdoconfig.xml

Posted by Lyle T Harris on January 08, 2010 at 01:19 AM PST #

Harris,

great to know that you got Jersey working on GAE.
I think your comments would be helpful to many.
May be you could send out a mail to the users mailing list at users@jersey.dev.java.net.

Posted by Naresh on January 08, 2010 at 05:31 PM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Naresh worked at Sun Microsystems for two years. During these two years he had worked on the Project Metro and Project Jersey.

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today