18
votes

I wrote a couple of REST services using Jersey 1.13 on JRE 1.6. Everything runs fine locally, but after I deploy to GAE I get this error:

****Uncaught exception from servlet
java.lang.IncompatibleClassChangeError: Implementing class
    at com.google.appengine.runtime.Request.process-139e1bda14d5aebc(Request.java)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
    at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
    at com.sun.jersey.api.core.ScanningResourceConfig.init(ScanningResourceConfig.java:79)
    at com.sun.jersey.api.core.PackagesResourceConfig.init(PackagesResourceConfig.java:104)
    at com.sun.jersey.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:78)
    at com.sun.jersey.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:89)
    at com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:700)
    at com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:678)
    at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:203)
    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:374)
    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:557)
    at javax.servlet.GenericServlet.init(GenericServlet.java:212)
    at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:440)
    at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:263)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:685)
    at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:452)
    at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:458)
    at com.google.tracing.TraceContext.runInContext(TraceContext.java:698)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:336)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:328)
    at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:456)
    at java.lang.Thread.run(Thread.java:679)****

Any help would be appreciated.

8

8 Answers

36
votes

This exception is caused by compatibility issues between asm-4.0.jar and asm-3.1.jar. With the new Version of AppEngine, asm-4.0.jar is used and it is not compatible with Jersey, which relies on asm-3.1.jar. To make Jersey still work on GAE 1.7, you have to remove the dependency on asm-4.0.jar.

See this post : http://cloudvane.com/2012/09/23/problem-with-google-appengine-and-jersey-with-java/

It s tested and verified, like that:

  1. add asm-3.3.1.jar to your war->lib
  2. add it to you re build path
  3. remove physically the asm-4.0.jar
  4. Project -> Properties -> Google -> AppEngine: switch Datanuclueus to v1

That s it!

9
votes

The instructions on this post took care of my problem.

Apparently the jersey-server 1.13 jar is compatible with asm3.1 and GAE 1.7.1 needs ASM 4. Using the Jar repackaging tool jarjar you can deploy a asm 3.1 jar that will play with asm 4.

You may need to use JarJar version 1.3 if 1.4 gives an error message.

4
votes

The new Jersey version 1.18.1 doens't depend on Asm 3, so it's compatible with GAE!

3
votes

Maybe this will help: java.lang.IncompatibleClassChangeError: Implementing class Mongo

It's not exactly the same class, but the problem occurs when you have a library with 2 different version jars. Make sure you did not include any extra libraries or (I'll explain what happened to me):

You have A-1.0.jar and A-1.0.jar has inside another jar, let's say B-1.0.jar, but you have included separately a B-2.0.jar and in this way the two different version B jars are the problem.

Make sure you did not make this.

1
votes

Same problem here, but I believe I've fixed it!

The trick was running a clean inside of eclipse, which notified me of the following error:

java.lang.RuntimeException: Unexpected exception
    at com.google.appengine.tools.enhancer.Enhancer.execute(Enhancer.java:76)
    at com.google.appengine.tools.enhancer.Enhance.<init>(Enhance.java:71)
    at com.google.appengine.tools.enhancer.Enhance.main(Enhance.java:51)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.appengine.tools.enhancer.Enhancer.execute(Enhancer.java:74)
    ... 2 more
Caused by: org.datanucleus.exceptions.NucleusUserException: You seem to have ASM v3 in the CLASSPATH and you need ASM v4
    at org.datanucleus.enhancer.DataNucleusEnhancer.<init>(DataNucleusEnhancer.java:173)
    at org.datanucleus.enhancer.DataNucleusEnhancer.main(DataNucleusEnhancer.java:1133)
    ... 7 more

The important bit . . .

Caused by: org.datanucleus.exceptions.NucleusUserException: You seem to have ASM v3 in the CLASSPATH and you need ASM v4

Apparently, GAE does not like having two versions of ASM loaded. On a whim, I went into the eclipse project properties and changed the datanucleus version from v2 to v1. I redeployed and now my app works. So much for catching these kinds of issues in the local dev environment . . .

I think I spent more time configuring GAE to run with jersey than I did actually writing the app. This may be my first and last GAE hosted app.

0
votes

Did you update your App engine's SDK? (Recently the App engine SDK was updated from 1.7.0 to 1.7.1.)

Try to revert your app engine's SDK to 1.7.0. I have tried many solutions that I found on the Internet, none of them worked for me, but this one worked.

I have no idea how I can safely change my app engine project's sdk version for now. If anyone knows how to change the SDK version of the app, please let me know.

0
votes

I got this error working on a maven project using Jersey-1.11 to develop a REST service: cglib-3.0 depends on asm-4.0, and so I excluded it, leaving asm-3.0 to stand. This is because the Jersey version I am using uses asm-3.0.

<dependency>
    <groupId>cglib</groupId>
    <artifactId>cglib</artifactId>
    <version>3.0</version>
    <exclusions>
        <exclusion>
            <artifactId>asm</artifactId>
            <groupId>org.ow2.asm</groupId>
        </exclusion>
    </exclusions>
</dependency>
0
votes

I changed the Persistence from JAP2 to JPA1 and it worked for me.