Search code examples
javajerseyjetty

Jetty, with Jersey, is not loading superclass


I'm working in Java web project running on a jetty web server. I have class A that inherit from B, at runtime I've found that the class A is not loading the methods of the class B. Class A:

public class A extends B{
...
}

And B:

public class B extends Serializable{

public void sampleMethod(){}
...
}

After adding some logging using Java reflection, when trying to find the superclass of A like so:

Class.forName("A").getSuperClass();

The previous line of code returns that the class Object is the superclass of A. I'm using JDK 8 and Jetty 9.

Also I'm using Jersey:

<dependency>
    <groupId>org.glassfish.jersey.containers</groupId>
    <artifactId>jersey-container-servlet</artifactId>
</dependency>

<dependency>
    <groupId>org.glassfish.jersey.inject</groupId>
    <artifactId>jersey-hk2</artifactId>
</dependency>

<dependency>
    <groupId>org.glassfish.hk2</groupId>
    <artifactId>guice-bridge</artifactId>
</dependency>

<dependency>
    <groupId>org.glassfish.jersey.ext</groupId>
    <artifactId>jersey-bean-validation</artifactId>
</dependency>

<dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-json-jackson</artifactId>
</dependency>

With this running configuration:

this.packages("com.orange.erable.notif.ws.external.resources");
this.register(CheckStatusResource.class);
//
// register custom jackson mapper
this.register(JacksonObjectMapperProvider.class);
// register roles allowed feature
this.register(RolesAllowedDynamicFeature.class);
// register auth filter
this.register(ContainerAuthExtFilter.class);
this.register(VersionFilterServlet.class);
this.register(SenderIdAuthFilter.class);
this.register(ModelValidationExceptionMapper.class);
this.register(DataValidationExceptionMapper.class);
this.register(DataNotificationExceptionMapper.class);
this.register(ValidationExceptionMapper.class);
this.register(JsonParseExceptionMapper.class, 1);
this.register(JsonProcessingExceptionMapper.class, 1);
this.register(JsonMappingExceptionMapper.class, 1);
this.register(QueryParamExceptionMapper.class, 1);
this.register(WebApplicationExceptionMapper.class);
this.register(GlobalExceptionMapper.class);
this.property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true);
this.register(DateParamConverterProvider.class);
this.register(PaginationBoundaryParamConverterProvider.class);
this.register(MappableExceptionMapper.class, 1);
this.register(MappableExceptionWrapperInterceptor.class);
this.register(JsonCustomExceptionMapper.class);

this.register(MultiPartFeature.class);

This issue is linked also to this problem.

EDIT: I'm using Jetty 9.22, I have tried to run the project on different machines with the same Jetty version, the described behaviour is just discovered in some of them.


Solution

  • I'm using Jetty 9.22, I have tried to run the project on different machines with the same Jetty version, the described behaviour is just discovered in some of them.

    That's a tell tale sign of multiple copies of the same class in multiple locations.

    Since you are using maven, consider running one of the duplicate class detection plugins to find out what you have going on.