1

While migrating our project from Java 8 to Java 11 modules, I have a question concerning the Java Module System (JPMS), especially to the required transitive directive. Lets assume we have four simple projects A, B, C and D with the following module declarations in module-info.java:

Project A

open module a {
    exports a;
}

Project B

open module b {
    exports b;
    requires transitive a;
}

Project C

open module c {
    exports c;
    requires transitive b;
}

Project D

open module d {
    requires transitive c;
}

Using Maven, we declared the dependencies D depends on C, C depends on B and B depends on A in the corresponding pom.xml files. Besides, each project contains a class file with the following content (the files for projects A, B and C are equivalent):

package d;
public class D {
    public static void main(String[] args) { 
        System.out.println("D");
    }
}

When running the classes using the default runtime configuration of Eclipse 2018-12, only class A, B and C runs without errors. But when I run class D I get: Error occurred during initialization of boot layer java.lang.module.FindException: Module a not found, required by b

In my understanding module a should be known to module b, module c and also module d due to applied requires transitive directives. But as you can see, at runtime this is not the case since module a is not set in the module-path (-p) but on the classpath of the generated command line:

C:\me\jdk-11.0.1\bin\javaw.exe
-Dfile.encoding=UTF-8 
-p "C:\me\workspace\d\target\classes;C:\me\workspace\c\target\classes;C:\me\workspace\b\target\classes"
-classpath "C:\me\workspace\a\target\classes"
-m d/d.D

So my question is: Why project A (C:\me\workspace\a\target\classes) has been added to the classpath and not to the module-path? Is this intended behaviour, and what do I have to change to get project D running in Eclipse?

If I move C:\me\workspace\a\target\classes to the -p argument list, everything works as I would expect but that's surely not the preferred way to go.

Thank you for any hints.

user27772
  • 522
  • 1
  • 4
  • 18
  • Does selection project _d_, in _Project > Properties: Java Build Path_, tab _Projects_ moving project _a_ from _Classpath_ to _Modulepath_ fix your issue? – howlger Jan 16 '19 at 13:26
  • @howlger: No, it didn't (btw., on this tab there were neither classpath nor modulepath entries shown, so I had not to move but to add a new entry for project _a_). But, if I add module _a_ it in my Run configuration > Dependencies > Modulepath entries it works. Meanwhile I also found that when I add _requires a_ in module _c_ or module _d_ it will also work. For now, it is a workaround that we can live with, but actually I want to understand why my _required transient_ directives are not enough to add all necessary modules to the _module-path_ when running class _D_. – user27772 Jan 16 '19 at 13:45
  • I filed a bug report here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=543766 – user27772 Jan 24 '19 at 08:20
  • Well, then you can give yourself an answer. Vote and comment on the bug if you want it to be fixed. – howlger Jan 24 '19 at 08:39

0 Answers0