torsdag 18 oktober 2012

Making Jersey work with Google App Engine

I was looking for a way to get Jersey work in a Google App Engine application that I am working with. Things seems to work just fine with the local test server, but deployed in the production environment it fails miserably.

The answer to the problem wasn't easy to find at all, but after plenty of googling i found a this post that the answer I was looking for.

I will here summarize the steps in a bit shorter post and hope that it will make this solution a little bit easier to find for others.

The problem boils down to the dependency of the asm jar file. The new versions of the GAE libraries use asm-4.0.jar but Jersey still depends on asm-3.1.jar. There are some posts out there that suggest that you can remove the asm-4.0.jar and change the data nucleus version to v1. WARNING!!! Doing this messed my eclipse up totally. I never got it to work properly again and had to reinstall it and all the plug-ins!

What Harry Wye suggests on his blog is to repackage the jar files depending on asm-3.1 using Jarjar Links. This worked fine for me using version 1.3. 1.4 gave me a manifest attribute error. I am not terribly experienced in Java, so I don't know why this happend or what to do about it (if you know... please share it in a comment on this page), but trying 1.3 did the work for me.

To repackage the jersey server jar (which is the only one depending on asm), you first have to create a file (rule.txt) with this content:
rule org.objectweb.asm.**  org.objectweb.asm3.@1

Then run jarjar:

java -jar jarjar-1.3.jar process testrules.txt asm-3.1.jar asm-3.1r.jarjava -jar jarjar-1.3.jar process testrules.txt jersey-server-1.14.jar jersey-server-1.14r.jar


Now you can deploy Jersey with the modified jars along with asm-4.0.jar in your GAE application.

Good Luck