Google App Engine + JAX-RS Jersey

This is a “how to” mini tutorial for running JAX-RS Jersey on Google App Engine Java environment.

Sandbox Environment:
Operating System:        Windows Vista
Integrated Development Environment: Eclipse Galileo

Setting up:

Start a Google App Engine project from Eclipse. Download Jersey 1.1.5-ea-SNAPSHOT from here . Explode the zip into a local folder. Grab the following jars and put them into GAEJ project’s /war/WEB-INF/lib folder.

asm-3.1.jar
jackson-core-asl-1.1.1.jar
jersey-client-1.1.5-ea-SNAPSHOT.jar
jersey-core-1.1.5-ea-SNAPSHOT.jar
jersey-json-1.1.5-ea-SNAPSHOT.jar
jersey-server-1.1.5-ea-SNAPSHOT.jar
jettison-1.1.jar
jsr311-api-1.1.1.jar

HelloWorldResource.java

Following user-guide.pdf create a resource class as follow. You can download the Jersey user guide from here.

package com.dclonline.jerseytest;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

//The Java class will be hosted at the URI path "/helloworld"
@Path("/helloworld")
public class HelloWorldResources {

	// The Java method will process HTTP GET requests
	@GET
	// The Java method will produce content identified by the MIME Media
	// type "text/plain"
	@Produces("text/plain")
	public String getClichedMessage() {
		// Return some cliched textual content
		return "Hello World";
	}
}

web.xml

Edit web.xml as follow.

<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
	<servlet>
        <servlet-name>Jersey Web Application</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>com.dclonline.jerseytest</param-value>
        </init-param>
         <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Jersey Web Application</servlet-name>
        <url-pattern>/resources/*</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
</web-app>

Test the service

After deployment to Google App Engine you can test the Hello World service using the following url.

http://<your google app engine app id>.appspot.com/resources/helloworld

A live link can be found here
http://meghbaksho22.appspot.com/resources/helloworld

18 Comments

  1. Razan Paul December 15, 2009 Reply
  2. Ahmed December 17, 2009 Reply
  3. Chris Pilsworth February 15, 2010 Reply
  4. Anish Sneh December 14, 2010 Reply
  5. sairn January 14, 2011 Reply
  6. sairn January 14, 2011 Reply
  7. E March 28, 2011 Reply
  8. ibsta April 19, 2011 Reply
    • iqbalyusuf April 19, 2011 Reply
  9. Joseph May 25, 2012 Reply
  10. riaz July 13, 2012 Reply
  11. trananhtho207 December 27, 2012 Reply
  12. trananhtho207 December 27, 2012 Reply
  13. Michele July 24, 2013 Reply
  14. Peter November 30, 2013 Reply
  15. Sakey May 18, 2014 Reply
  16. Jérémy Bras September 28, 2014 Reply

Add a Comment

Your email address will not be published. Required fields are marked *