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.

4
  • 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, 2019 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, 2019 at 13:45
  • I filed a bug report here: bugs.eclipse.org/bugs/show_bug.cgi?id=543766
    – user27772
    Jan 24, 2019 at 8: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, 2019 at 8:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.