1

Here is my scenario. I have a client jar that uses glassfish jersey version 2.17 jar. Now I am changing an application to use this client jar that will be deployed in Spark cluster. The spark uses com.sun.jersey version 1.9 jar.

In the client jar, when a jersey request is made, it refers javax.ws.rs.core.MultivaluedMap from javax.ws.rs-api-2.0.1.jar in ClientRequest.accept method. Unfortunately this same class with the same package name is also present in jersey-core-1.9.jar which is referred by com.sun.jersey which is used my Apache spark. Now the javax.ws.rs-api-2.0.1.jar version contains a method called as addAll(...) which is not present in jersey-core-1.9.jar version. This causes runtime exceptions when I try to run my application in spark cluster.

I tried to explicitly refer to javax.ws.rs-api-2.0.1.jar as dependency in my client jar to set the linking happen properly in my client jar, but still no use. It links back to the javax.ws.rs.core.MultivaluedMap from jersey-core-1.9.jar which causes MethodNotFound runtime exception. Any suggestions to solve this?

Do I have to make my client to use com.sun.jersey? In this case, I have few other projects which make use of glassfish jersey. So I suspect this will error out there.

edit:

My application pom has this dependency

<dependency>
            <groupId>org.apache.phoenix</groupId>
            <artifactId>phoenix-spark</artifactId>
            <version>4.6.0-HBase</version>
            <scope>provided</scope>
</dependency>

My client jar that I am trying to use in my spark application has this dependency,

<dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-client</artifactId>
        <version>2.17</version>
</dependency>

Hence I need a proper way of fixing this. Kindly provide your suggestions.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
sriram
  • 712
  • 8
  • 26
  • I think you are confused. [Apache Spark](http://spark.apache.org/) doesn't need Jersey. Perhaps you mean Sparkjava, the web framework? – OneCricketeer Aug 01 '16 at 20:09
  • My application uses phoenix-spark jar and this will run in the spark cluster. In the pom.xml of phoenix-spark jar, it has com.sun.jersey as dependency. Also the phoenix-spark has spark-core as dependency which in turn again uses this com.sun.jersey as pom.xml dependency. Here is where the conflict is. – sriram Aug 01 '16 at 20:25
  • So, you are or are not running a web server? Just using the core libraries in some pom.xml, for example? – OneCricketeer Aug 01 '16 at 20:29
  • Thanks for getting back. The application is not a web server, it is a spark job which uses this client to make Http calls. Hence this spark job contains spark dependencies in pom.xml which brings in com.sun.jersey. – sriram Aug 01 '16 at 20:42
  • Can you please share the pom here? You should be able to exclude one of those conflicting dependencies – OneCricketeer Aug 01 '16 at 20:45
  • Sure. Added. Kindly have a look and mention if it is sufficient – sriram Aug 01 '16 at 21:48
  • Content-wise the question is okay, other than the description is hard to follow. Unfortunately, I don't have a way to setup Spark / Glassfish to really help with the problem – OneCricketeer Aug 01 '16 at 21:52
  • Thanks a lot for trying to help me here. The problem happens due to the diamond structure that is getting formed while importing the dependencies. Example ) A -> B -> C, D -> E -> C! , D -> A -> C. Here C! is another jar containing the same classname from C. Hence when D calls A, instead of A -> C , it is wrongly calling A -> C! – sriram Aug 01 '16 at 21:58
  • Here is an example of an exclusion group that you could try applying to one of the dependencies to "cut it out" http://stackoverflow.com/a/37297894/2308683 – OneCricketeer Aug 01 '16 at 22:03
  • There is a problem with exclusion here as the glassfish jar which is latest version don't think can support all of the requirements of com sun jersey jar. In the other words, both of these jars are from different providers and hence not guaranteed to be backward compatible. Just going to rewrite my client to downgrade to com sun jersey to prevent these issues. Alas! I would love not to! – sriram Aug 01 '16 at 22:53

0 Answers0