I am compiling my legacy source code using JDK 9.0.1 as follows:
javac --add-modules=java.base,java.xml.ws -cp lib\jsr305.jar;lib\javax.annotation-api-1.2.jar TestJava.java
It gives an error because the annotations defined in jsr305.jar
are not visible due to split module issue. The error is as follows:
TestJava.java:3: error: cannot find symbol
import javax.annotation.Nonnull;
^
symbol: class Nonnull
location: package javax.annotation
Here the module java.xml.ws.annotation
is getting loaded since it is required for java.xml.ws
. So it is ignoring the types in jsr305.jar
. I don't want this module to be loaded but refer all its annotation types from javax.annotation-api-1.2.jar
. I don't want to do --patch-module
either because it would break in future releases.
If I use --limit-module=java.xml.ws.annotation
it gives the same error. If I remove java.xml.ws
from -add-modules
, it compiles successfully but I need to export few APIs from it so can't remove it. Is there any way I can load module java.xml.ws
but not java.xml.ws.annotation
?
EDIT : I think I have added some confusion by giving an example of split between java.xml.ws.annotaion and jsr305.jar. Though it's my actual problem, I am more interested in knowing - can I avoid loading a transitively dependent module, say loading java.xml.ws
without loading java.xml.ws.annotation
? As per my understanding in JEP 261 it says,
--limit-modules <module>(,<module>)*
where
<module>
is a module name. The effect of this option is to limit the observable modules to those in the transitive closure of the named modules plus the main module, if any, plus any further modules specified via the --add-modules option.
So, why isn't --limit-module
preventing java.xml.ws.annotation
from loading?