4

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?

Community
  • 1
  • 1
Madjosz
  • 509
  • 1
  • 5
  • 13
  • That doesn't look like the Eclipse/OSGi class loaders. You should be using 'Run As > Eclipse Application' to run plug-in code. – greg-449 Mar 25 '18 at 18:35
  • Thats right, I run this project using "Run As -> Java Application" which executes with jdk9\bin\javaw.exe. But in jdk1.8 the dependecies where resolved correctly. How can I run this microproject as an Eclipse Application? – Madjosz Mar 25 '18 at 19:02
  • I'm not sure I understand the goal: do you want to run this program with or without OSGi? When using OSGi, the answer regarding reexport should do it. Otherwise, do you have any entries in the Build Path besides "Plug-in Dependencies"? Do entries appear under Classpath or under Modulepath? What does the launch config look like? – Stephan Herrmann Mar 26 '18 at 23:05
  • We used the Eclipse Plugin-Projects as kind of a pre JDK 9 module system to manage the dependencies of our projects, but the projects itself are planned to run without OSGi. They are built using the "Export as -> Runnable JAR"-Feature of Eclipse, where OSGi resolves the dependencies for us. The dependencies appear in the Classpath under Plug-in Dependencies. There are no special launch configurations, just the default, which is created by Eclipse when you "Run as -> Java Application". – Madjosz Mar 27 '18 at 09:03
  • This is a bug in Eclipse: https://bugs.eclipse.org/bugs/show_bug.cgi?id=534884 – isnot2bad Aug 02 '18 at 12:26

1 Answers1

2

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.

benez
  • 1,856
  • 22
  • 28
  • Although this works, it is just a workaround that does not work well for larger projects with multiple bundles. As transitive dependencies work when executed with Java 8, it seems to be some kind of eclipse bug!? – isnot2bad Aug 02 '18 at 12:00