-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) {
System.out.println(javax.annotation.Generated.class.getName());
}
}
As expected, this will not compile with JDK 9
"c:\Program Files\Java\jdk-9.0.1\bin\javac.exe" TestAnnotation.java
TestAnnotation.java:3: error: package javax.annotation is not visible
System.out.println(javax.annotation.Generated.class.getName());
^
(package javax.annotation is declared in module java.xml.ws.annotation, which is not in the module graph)
1 error
Ignoring the error message (and using java.xml.ws instead of the suggested java.xml.ws.annotation), I can compile with it
"c:\Program Files\Java\jdk-9.0.1\bin\javac.exe" --add-modules java.xml.ws TestAnnotation.java
However, looking at the module graph module java.xml.ws does not depend on the module java .xml.ws.annotation, which exports the javax.annotation package. p>
How is this possible to compile (by the way, run)?
Solution
java.xml.ws
does rely on java.xml.ws.annotation
: http://hg.openjdk.java.net/jdk/jdk/file/68c6f57c40d4/src/java.xml.ws/share/classes/module-info.java#l46
module java.xml.ws {
requires java.desktop;
requires java.logging;
requires java.management;
requires java.xml.ws.annotation;
...
I don’t know why this dependency is missing in this picture. Probably they only want to show key links.