2

The exception is raised during the following call

Response response = client().target(rpTarget())
    .path(clusterPath())
    .queryParam("api-version", csmv2ApiVersion())
    .request(MediaType.APPLICATION_JSON)
    .get();

The full stack of the exception is

java.lang.NoSuchMethodError: javax.ws.rs.core.MultivaluedMap.addAll(Ljava/lang/Object;[Ljava/lang/Object;)V
  at org.glassfish.jersey.client.ClientRequest.accept(ClientRequest.java:335)
  at org.glassfish.jersey.client.JerseyWebTarget.request(JerseyWebTarget.java:221)
  at org.glassfish.jersey.client.JerseyWebTarget.request(JerseyWebTarget.java:59)

....

I build my application jar using "mvn package" and the build output has the following

[INFO] Including javax.ws.rs:javax.ws.rs-api:jar:2.0.1 in the shaded jar.

[INFO] Including org.glassfish.jersey.core:jersey-common:jar:2.19 in the shaded jar.

I seem to be using the latest version of javax.ws.rs-api.jar that seems to contain the definition of MultivaluedMap.addAll method, but I still keep getting this exception.

Could you please let me know what I am missing?

ParkerHalo
  • 4,341
  • 9
  • 29
  • 51
Rajesh
  • 21
  • 1
  • 1
  • 3
  • you call a method that does not exist - check again the doc of your lib to match the arguments of the call with the method definition – Frederic Henri Dec 18 '15 at 08:31
  • This issue is still not resolved for me. During compilation using maven, I saw a warning stating that javax.ws.rs-api.jar v2.0.1 and jersey-core.jar v1.9 both implemented MultivaluedMap class. The definition in jersey-core.jar did not have the method addAll while the one in javax.ws.rs-api.jar had the method. So i removed all dependencies to jersey-core.jar v1.9 using the 'exclusions' tag in my pom.xml file. In spite of these changes I still see the same error message when I run my application. I am using JDK version jdk1.7.0_79 to build and 1.7.0_91 to run my application. Appreciate any help – Rajesh Dec 31 '15 at 01:06

1 Answers1

3

It looks like you may have different versions of MultivaluedMap at compile time and run time. So when using maven you compile against a specific version of the library with no errors, but depending on how you compile it you may actually be using a different version at runtime (eg one built in to the server) which does not have this method, resulting in the exception. Check on your server which version it uses and see if there's a difference between that and the one you specify in your pom.xml. Also check the scope attribute for that dependency, default I believe is "compile" which will actually compile the library into your jar file, "provided" will not compile the library in and expect it to be provided by some other means.

The important thing to note here is that versions of libraries you use when compiling are not necessarily the same versions you use at run time. It makes things easier if you can make sure the versions on the server are the ones you want, rather than having two different versions.

See section 2.3 here, it has some information about the javax.ws.rs maven dependencies required on glassfish.

ewanc
  • 1,284
  • 1
  • 12
  • 23