0

I am implementing an API wrapper in Java 1.8 using Jersey 2.27. When I run an Invocation.Builder.get(), I get the following error:

Exception in thread "main" java.lang.IllegalStateException: InjectionManagerFactory not found.
        at org.glassfish.jersey.internal.inject.Injections.lambda$lookupInjectionManagerFactory$0(Injections.java:98)
...

Following the guidance here, I update my Maven pom.xml file with the following dependencies:

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

<dependency>
  <groupId>org.glassfish.jersey.inject</groupId>
  <artifactId>jersey-hk2</artifactId>
  <version>2.27</version>
</dependency>

Now, when I compile using Maven, I get the following warning:

[WARNING] javax.inject-1.jar, javax.inject-2.5.0-b42.jar define 6 overlappping classes:
[WARNING]   - javax.inject.Inject
[WARNING]   - javax.inject.Singleton
[WARNING]   - javax.inject.Scope
[WARNING]   - javax.inject.Named
[WARNING]   - javax.inject.Provider
[WARNING]   - javax.inject.Qualifier
[WARNING] maven-shade-plugin has detected that some .class files
[WARNING] are present in two or more JARs. When this happens, only
[WARNING] one single version of the class is copied in the uberjar.
[WARNING] Usually this is not harmful and you can skeep these
[WARNING] warnings, otherwise try to manually exclude artifacts
[WARNING] based on mvn dependency:tree -Ddetail=true and the above
[WARNING] output
[WARNING] See http://docs.codehaus.org/display/MAVENUSER/Shade+Plugin

From mvn dependency:tree I can see that the two dependencies I showed above are causing this collision (I highlighted the lines in question):

[INFO] +- org.glassfish.jersey.core:jersey-client:jar:2.27:compile
[INFO] |  +- javax.ws.rs:javax.ws.rs-api:jar:2.1:compile
[INFO] |  +- org.glassfish.jersey.core:jersey-common:jar:2.27:compile
[INFO] |  |  +- javax.annotation:javax.annotation-api:jar:1.2:compile
[INFO] |  |  \- org.glassfish.hk2:osgi-resource-locator:jar:1.0.1:compile
>> [INFO] |  \- org.glassfish.hk2.external:javax.inject:jar:2.5.0-b42:compile
[INFO] +- org.glassfish.jersey.inject:jersey-hk2:jar:2.27:compile
[INFO] |  \- org.glassfish.hk2:hk2-locator:jar:2.5.0-b42:compile
[INFO] |     +- org.glassfish.hk2.external:aopalliance-repackaged:jar:2.5.0-b42:compile
[INFO] |     +- org.glassfish.hk2:hk2-api:jar:2.5.0-b42:compile
>> [INFO] |     |  \- javax.inject:javax.inject:jar:1:compile
[INFO] |     +- org.glassfish.hk2:hk2-utils:jar:2.5.0-b42:compile
[INFO] |     \- org.javassist:javassist:jar:3.22.0-CR2:compile

Why are these two dependencies, that should theoretically be updated together, causing this collision?

kingledion
  • 2,263
  • 3
  • 25
  • 39
  • These are warning, not errors of any kind... _"Usually this is not harmful and you can skeep these warnings"_. It's not going hurt. Overlapping classes are going to happen. As long as there are no version incompatibilities, you should be find. – Paul Samsotha Oct 23 '18 at 19:00
  • @PaulSamsotha I have specific concerns that this collision will cause problems once I jar this code and integrate it with other code. Also, there very well may be version incompatibilities between v1.0 and v2.5. I'm trying to learn about what is causing this so I can avoid future problems down the road. – kingledion Oct 23 '18 at 19:02
  • 1
    There are two different javax.inject jars, one looks like its from HK2 and the other is the standard jar. This will not cause any problem. They are the same class and only one will be packaged into the uber jar. These are very standard classes, and you should not expect any changes in the one from HK2. Don't worry about this. – Paul Samsotha Oct 23 '18 at 19:05
  • While @PaulSamsotha, could be correct that this particular dependency collision may not create problems. However, I did once encounter MethodNotFound while different versions of javax.activation as on the classpath. In general duplication of dependencies should be avoided. Once mechanism is to explicitly exclude the dependencies or use dependencyManagement in Maven as another. Especially one should be vigilant of dependencies being duplicated on web-app and container class paths through transitive dependencies. – Ironluca Feb 05 '22 at 20:49

0 Answers0