I am implementing a module for Java11 and want to use annotations from JSR250 (javax.annotation.PostConstruct and javax.annotation.PreDestroy).
I already changed the according dependency from:
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>jsr250-api</artifactId>
<version>1.0</version>
</dependency>
to this:
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
That artifact javax.annotation-api-1.3.2.jar
contains in META-INF/MANIFEST.MF
this line:
Automatic-Module-Name: java.annotation
Hence, I tried to add this to my module-info.java file:
requires java.annotation;
However, I get an error for this import:
import javax.annotation.PostConstruct;
The error message is:
The type javax.annotation.PostConstruct is not accessible
I already studied the following related questions but am still unable to resolve my issue:
- I can't use @PostConstruct and @PostDestroy with Java 11
- Intellij: how to add java.annotation module for javax.annotation.PostConstruct (Please note that I am using Eclipse with JDK11 and that does not contain a module
java.xml.ws.annotation
).