Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoSuchFieldError: INCLUDE_ALL

I am using Jersey with Spring on GAE.
I get the following exception:

Uncaught exception from servlet
java.lang.NoSuchFieldError: INCLUDE_ALL
    at org.glassfish.jersey.server.ResourceConfig$State.<init>    (ResourceConfig.java:110)
    at org.glassfish.jersey.server.ResourceConfig.<init>(ResourceConfig.java:351)
    at org.glassfish.jersey.server.ResourceConfig$WrappingResourceConfig.<init>(ResourceConfig.java:1014)
    at org.glassfish.jersey.server.ResourceConfig.forApplicationClass(ResourceConfig.java:325)
    at org.glassfish.jersey.servlet.WebComponent.createResourceConfig(WebComponent.java:442)
    at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:294)
    at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:167)
    at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:349)
    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.apphosting.runtime.jetty.AppVersionHandlerMap.createHandler(AppVersionHandlerMap.java:219)
    at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.getHandler(AppVersionHandlerMap.java:194)
    at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:134)
    at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:446)
    at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:437)
    at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:444)
    at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:188)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:308)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:300)
    at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:441)
    at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:251)
    at java.lang.Thread.run(Thread.java:724)

Looking at Jersey Code I see that this is were the exception is thrown:

    public State() {
        super(RuntimeType.SERVER, ComponentBag.INCLUDE_ALL);

Looking at 'ComponentBag' I can see the public field that cant be found in runtime.

public static final Predicate<ContractProvider> INCLUDE_ALL = Predicates.alwaysTrue();

Inside the 'State' constructor, the field 'INCLUDE_ALL' of 'ComponentBag' cant be found in runtime.
It looks like a classpath issue but I cant find what is wrong.
I am using Maven - here are the relevant parts of my POM.

   ... 
<properties>
    <appengine.app.version>5</appengine.app.version>
    <appengine.target.version>1.8.9</appengine.target.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <jersey.version>2.7</jersey.version>
    <spring.version>3.2.3.RELEASE</spring.version>
</properties>
   ...
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>${spring.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>${spring.version}</version>
    <exclusions>
        <exclusion>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
        </exclusion>
    </exclusions>
</dependency>

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>${spring.version}</version>
</dependency>

<dependency>
    <groupId>org.glassfish.jersey.ext</groupId>
    <artifactId>jersey-spring3</artifactId>
    <version>${jersey.version}</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-json-jackson</artifactId>
    <version>${jersey.version}</version>
</dependency>
    ...
like image 616
balderman Avatar asked Apr 13 '14 20:04

balderman


1 Answers

If someone ever stumbles across this question (or if it still is relevant), I've found adding -verbose:class to the command line VM options helps you figure out where exactly this exception stems from.

ResourceConfig comes from jersey-server-2.22.1.jar. I've solved this issue by deleting all of my jars from WEB-INF/lib and adding them from maven.

like image 105
Dan Bachar Avatar answered Sep 23 '22 04:09

Dan Bachar