Annotations across modules
Philippe Marschall
pm at netcetera.ch
Mon Nov 16 11:19:48 UTC 2015
On 12.11.15 14:50, Stephen Colebourne wrote:
> My understanding of annotations today is that annotations are not
> required at runtime. ie. if an annotation is placed into a class at
> compile time but the .class file for the annotation is not available
> on the runtime classpath. then there is no error.
>
> Does this change in any way with modules?
>
> My specific case is wrt @ConstructorProperties which is in java.beans.
> In 9, a user may run my software without the java.beans module. Can I
> safely assume that if the annotation is available on the compile
> module path but not the runtime module path, everything will be OK
> (ie. no error)?
My understanding is that you can't have optional dependencies. So if you
have @ConstructorProperties in your source you also need to have a
java.desktop module dependency in your module-info.java. If your library
is in the module path the java.desktop module then it needs to be
present at runtime.
The only option you have is to make your jar not a modular jar by one of
those:
- not providing a module-info.class
- not putting your module in the module path
Cheers
Philippe
More information about the jigsaw-dev
mailing list