Maven dependencies wrong Jersey class chosen at runtime

Viewed 372

I have a Java Servlet project with Maven and Tomcat which contains the following two dependencies (amongst many others):

<dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-server</artifactId>
    <version>2.25.1</version>
</dependency>
<dependency>
    <groupId>com.microsoft.azure</groupId>
    <artifactId>azure-serviceruntime</artifactId>
    <version>0.6.0</version>
</dependency>

jersey-server includes javax.ws.rs-api:2.0.1, and azure-serviceruntime includes jersey-core:1.13 which both contain the class Application in the package javax.ws.rs.core.

Searching the Application type in Eclipse shows the following (to clarify): The two Application classes

The problem is that at runtime the wrong Application class is used which results in the following error when starting Tomcat:

java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;

For every servlet.

I tried excluding jersey-core from the azure-serviceruntime but then the servlets don't seem to load at all. I also tried to add javax.ws.rs-api as a direct dependency but that also didn't work. The most unexplainable part is that it does work on Windows but not on Linux... I also tried relocating classes/packages with maven shade but without any success.

How can I tell Java to use the latest Application class?

2 Answers
Related