3

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 does not compile using 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 get it to compile using

"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 module java.xml.ws.annotation, which exports the javax.annotation package.

How is it possible this does compile (and run, btw)?

1 Answer 1

3

java.xml.ws does depend 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 have no idea why this dependency is missing in that picture. Probably they wanted to show only the key links.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks! Too bad it's not in the summary either.
On second thought, they probably only show the transitive dependencies
@BrechtYperman Yes, you seem to be right. They show only transitive ones.
Not just the picture, what could be added to the answer a little further is how is adding one module bringing the other(without transitive dependence) into the module-graph?

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.