Maven. Transitive dependencies

My project P depends on dependency A [with a compile scope] which depends on dependency B [with a compile scope].

Unless B is an optional dependency of A, B should be a dependency of P with a "compile(*)" scope (see the table of Dependency Scope and read the note) and should thus be available at runtime.

However, there is a NoClassDefFoundError thrown at runtime of P, which stems from missing B jars.

Since you're running the project under Eclipse, the class path is setup for you so I'll exclude a mistake at this level. This leaves us with the case of the optional dependency.

PS: A very useful tool to investigate this kind of problem is dependency:tree.


If this dependency A has a compile scope - sure, it should have been downloaded and more over - made available in the classpath of the project. But if it had provided scope that would be the case, since provided deps would not be packaged with the application by Maven.

Btw how are you running this project - not running in the proper way might cause such problems as well and this is a very good guess. For example - if you're using maven exec plugin - maven will setup properly the classpath for you, but otherwise - you should setup it yourself(or build a jar with dependencies with the assembly plugin).