0

In working through a different issue I am having, I decided to upgrade from Jersey 1.19 to 2.22.1 with the hope that the directions I was looking at were not applicable to 1.x and upgrading would fix my problem.

Along the way I ran into an odd issue. I upgraded my maven dependencies to 2.x and recompiled. No issues there. I got all the runtime dependencies I could find into my Jetty server but there was one thing I got stuck on. when I would go to run a simple GET, I would get the following stack trace:

    java.lang.ClassNotFoundException: com.sun.ws.rs.ext.RuntimeDelegateImpl
      at java.net.URLClassLoader$1.run(Unknown Source)
      at java.net.URLClassLoader$1.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Unknown Source)
      at javax.ws.rs.ext.FactoryFinder.newInstance(FactoryFinder.java:62)
      at javax.ws.rs.ext.FactoryFinder.find(FactoryFinder.java:155)
      at javax.ws.rs.ext.RuntimeDelegate.findDelegate(RuntimeDelegate.java:105)
      at javax.ws.rs.ext.RuntimeDelegate.getInstance(RuntimeDelegate.java:91)
      at javax.ws.rs.core.EntityTag.<clinit>(EntityTag.java:35)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Unknown Source)
      at sun.proxy.$Proxy21.<clinit>(Unknown Source)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
      at java.lang.reflect.Constructor.newInstance(Unknown Source)
      at java.lang.reflect.Proxy.newInstance(Unknown Source)
      at java.lang.reflect.Proxy.newProxyInstance(Unknown Source)
      at com.sun.jersey.server.impl.application.WebApplicationImpl.createProxy(WebApplicationImpl.java:1592)
      at com.sun.jersey.server.impl.application.WebApplicationImpl.<init>(WebApplicationImpl.java:320)
      at com.sun.jersey.server.impl.container.WebApplicationProviderImpl.createWebApplication(WebApplicationProviderImpl.java:55)
      at com.sun.jersey.spi.container.WebApplicationFactory.createWebApplication(WebApplicationFactory.java:66)
      at com.sun.jersey.spi.container.servlet.ServletContainer.create(ServletContainer.java:392)
      at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.create(ServletContainer.java:307)
      at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:603)
      at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210)
      at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:374)
      at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:557)

FYI: This is a really barebones setup. It's just Jetty with the Jersey servlet-container.

This class didn't come down with the dependencies for 2.22.1 and when I tried to find a reference to what jar this might come from, everything pointed back to jersey-bundle which doesn't seem to be a jar under org.glassfish.jersey.core. There is a file called com.sun.ws.rs.ext.RuntimeDelegateImpl in the jersey-server-2.22.1.jar file under META-INF/services with a single line in it that says: org.glassfish.jersey.server.internal.RuntimeDelegateImpl

For kicks, I threw the jersey-bundle-1.19.jar file into the lib for the web app, and viola! my (very simple) app was working as before.

Id there something messed up with my setup here? I don't understand why there's a reference to a class in the jersey 2.x that isn't included in the Maven dependencies.

JimmyJames
  • 1,356
  • 1
  • 12
  • 24
  • As @peeskillet has pointed out on [other](http://stackoverflow.com/a/30684833/775715) Stackoverflow questions, [don't](http://stackoverflow.com/questions/32786766/allow-cross-domain-request-to-jersey-web-services/32817008#comment53423803_32786766) [mix](http://stackoverflow.com/questions/29964416/clientbuilder-issue#comment48049082_29964416) Jersey 1.x and Jersey 2.x in the same project. – Joakim Erdfelt Dec 07 '15 at 22:12
  • At a guess, I would reckon when you upgraded from Jersey 1.19 to 2.22.1 you missed a dependency and were actually mixing 1.19 and 2.22.1 and that's why it didn't work. Adding the old 1.19 bundle probably brought in enough of the original 1.19 dependencies to make it work again. Did you try doing a dependency:analyze when you had 2.22.1 jersey and looking for 1.19 dependency versions? – sisyphus Dec 07 '15 at 22:36
  • How about showing your dependencies and how you create the server. You can also see a complete example [here](http://stackoverflow.com/a/28734049/2587435) – Paul Samsotha Dec 08 '15 at 01:46
  • _"Jersey 2.x Requires 1.x libs?"_. No, but the configurations are completely different – Paul Samsotha Dec 08 '15 at 01:47

1 Answers1

0

I had the jersey 1.x jars into the extensions folder of Jetty with the exception of this one jar. I also failed to update the servlet class to org.glassfish.jersey.servlet.ServletContainer in my web.xml. This was why I was still getting the 1.x dependencies.

JimmyJames
  • 1,356
  • 1
  • 12
  • 24