jersey2-guice icon indicating copy to clipboard operation
jersey2-guice copied to clipboard

It appears jersey2-guice-spi is either not present or in conflict with some other Jar

Open xinranxiao opened this issue 9 years ago • 4 comments

I'm trying to use this package with Dropwizard and Guice, using the "complex example" code in the wiki of this repo. I'm currently getting this error when I start my application

.... It appears jersey2-guice-spi is either not present or in conflict with some other Jar: ServiceLocatorGeneratorImpl(hk2-locator, 1911168986)

It looks like this is related to this (https://github.com/Squarespace/jersey2-guice/pull/37)... I did some monkeypatching with JerseyGuiceUtils.java and printed out the names of the providers within lookupSPI:

for (ServiceLocatorGenerator generator : providers) {
  System.out.println(generator.getClass().getName());
}

And I get:

org.jvnet.hk2.external.generator.ServiceLocatorGeneratorImpl
com.squarespace.jersey2.guice.GuiceServiceLocatorGeneratorStub
org.jvnet.hk2.external.generator.ServiceLocatorGeneratorImpl

Currently the code just takes the first one... however it looks like the second one is the right class. Would it be better to just loop over the providers and check all of them?

xinranxiao avatar May 23 '16 04:05 xinranxiao

@xinranxiao yea it seems something is initializing Jersey before you do. Are you initializing jersey2-guice straight from the main() method or as early as possible and definitively before DW which will trip Jersey.

Secondly I'd look at the classpath and the order in which JARs are being loaded. The jersey2-guice-spi JAR is purposely called 0-jersey2-guice-spi to move it to the front (but there may be no guarantee). But this is optional and it should work if initialization happens in the main() method.

rkapsi avatar May 23 '16 15:05 rkapsi

Came here from dropwizard-guice - also encountering what looks like the same issue.

I'm seeing:

WARN [2017-09-21 16:41:23,236] com.squarespace.jersey2.guice.JerseyGuiceUtils: It appears jersey2-guice-spi is either not present or in conflict with some other Jar: ServiceLocatorGeneratorImpl(hk2-locator, 832648870) Exception in thread "main" java.lang.LinkageError: loader (instance of sun/misc/Launcher$AppClassLoader): attempted duplicate class definition for name: "org/glassfish/hk2/api/ServiceLocatorState" at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:760) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:467) at java.net.URLClassLoader.access$100(URLClassLoader.java:73) at java.net.URLClassLoader$1.run(URLClassLoader.java:368) at java.net.URLClassLoader$1.run(URLClassLoader.java:362) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:361) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at org.jvnet.hk2.internal.ServiceLocatorImpl.<init>(ServiceLocatorImpl.java:207) at com.squarespace.jersey2.guice.GuiceServiceLocator.<init>(GuiceServiceLocator.java:29) at com.squarespace.jersey2.guice.JerseyGuiceUtils.newServiceLocator(JerseyGuiceUtils.java:248) at com.squarespace.jersey2.guice.JerseyGuiceUtils.newServiceLocator(JerseyGuiceUtils.java:227) at com.squarespace.jersey2.guice.JerseyGuiceUtils.newServiceLocator(JerseyGuiceUtils.java:220) at com.hubspot.dropwizard.guice.GuiceBundle.initialize(GuiceBundle.java:126)

tmwilder avatar Sep 21 '17 23:09 tmwilder

This issue hasn't seen a real update for over 2 years. Is this project currently dead/inactive? I'm seeing the same issue when trying to using dropwizard-guice and swagger2.0. Both use this automated way of discovering resources.

jessechahal avatar Jun 19 '18 23:06 jessechahal

Hello, the project is currently inactive. We don't have any Jersey 2 w/ Guice projects.

rkapsi avatar Jun 21 '18 18:06 rkapsi