Maven dependencies Jersey selected at runtime
I have a Java Servlet project with Maven and Tomcat that contains the following two dependencies (among 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
, but azure-serviceruntime
includes jersey-core:1.13
that contain the class Application
in the package javax.ws.rs.core
.
Searching for a type Application
in Eclipse reveals the following (for clarification):
The problem is that the wrong class is being used at runtime Application
, which results in the following error when starting Tomcat:
java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;
For each servlet.
I tried to exclude jersey-core
from azure-serviceruntime
, but then the servlets don't load at all. I also tried adding javax.ws.rs-api
as a direct dependency, but that didn't work either. The most inexplicable part is that it works on Windows, but not Linux ... I also tried to move maven-tinged classes / packages, but without any success.
How can I tell Java to use the latter class Application
?
source to share
I think it's best to use dependency exclusion to exclude jersey-core: 1.13 from azure-serviceruntime dependency:
<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>
<exclusions>
<exclusion>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-core</artifactId>
</exclusion>
</exclusions>
</dependency>
source to share