Search code examples
javadependenciesjava-9eclipse-oxygentransitive-dependency

transitive dependencies in Eclipse Plugin-Project with Java 9


It seems, that in my Eclipse Oxygen 3 transitive dependencies are not resolved in Plugin-Projects. Consider the following Project with A depending solely on B, and B depending on C: Minimal Project with transitive Dependencies While running A in JDK 1.8 turns out fine (as expected), in JDK 9 I get the well known

Exception in thread "main" java.lang.NoClassDefFoundError: c/C
    at b.B.<init>(B.java:9)
    at a.A.main(A.java:8)
Caused by: java.lang.ClassNotFoundException: c.C
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
    ... 2 more

I know, I have not declared any modules but I thought, omitting them just keeps the project as it is, even in JDK 9. When I import project C directly in the A MANIFEST.MF, then all works as in JDK 1.8. So how to get the projects running, if possible without declaring modules?


Solution

  • You can modify the MANIFEST.MF in project B to reexport its dependency to project C:

    • open the MANIFEST.MF from project B in the MANIFEST-Editor
    • switch to the Dependencies tab
    • select the dependency to project C and click "Properties..."
    • select "Reexport this dependency"

    Keep in mind that this change will also make classes from project C available in project A, creating an explicit dependency from A to C when using those classes.