Javac –add-modules Add multiple modules

-add-modules Add multiple modules… here is a solution to the problem.

-add-modules Add multiple modules

I have a very simple Java class

public class TestAnnotation {
    public static void main(String[] args) {

As expected, this will not compile with JDK 9

"c:\Program Files\Java\jdk-9.0.1\bin\javac.exe" error: package javax.annotation is not visible
  (package javax.annotation is declared in module, which is not in the module graph)
1 error

Ignoring the error message (and using instead of the suggested, I can compile with it

"c:\Program Files\Java\jdk-9.0.1\bin\javac.exe" --add-modules

However, looking at the module graph module does not depend on the module java, which exports the javax.annotation package. p>

How is this possible to compile (by the way, run)?

Solution does rely on

module {
    requires java.desktop;
    requires java.logging;

I don’t know why this dependency is missing in this picture. Probably they only want to show key links.

Related Problems and Solutions