1

I am getting NoClassDefFoundError while trying to load a class which seems to be due to dependency version conflict.

Project A -> Project B -> Project C.

We have included version 2.0 for Project C within Project A.

whereas

Project B needs version 1.0 for Project C.

Right now when Project B code tries to load the class from Project C, it gets version 2.0.

Is there a way, I can explicitly define to refer to Project C (version 1.0 ) if project B tries to do so and in all other cases it should pick version 2.0

I mean the way we can exclude the transitive dependency, Is there a way to explicitly define inclusion ( only for the reference from the respective project and not the whole application code ).

Thanks.

Vivek Vermani
  • 1,934
  • 18
  • 45
  • Without posting you `pom.xml` files and a `mvn dependency:tree`, it would be very hard for anyone to figure out what's going on. – carlspring Jan 08 '16 at 14:57

1 Answers1

0

I seriously doubt that. If I understand the question correctly, your build would result in loading the jar of project C in two different versions simultaneously into the JVM (one for Project B and one for Project A). As they probably share the same packages and class names, there is no way for the JVM to distinguish them.

If project C is your own project and the change from version 1.0 to 2.0 breaks something, I would think about using a new package name, like org.example.c2 instead of org.example.c (like e.g. in the Apache commons-lang project).

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142