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:
java.xml.ws.annotation
). The error occurred only in Eclipse. It actually turned out that other unrelated compile errors where causing some side effects in Eclipse. After resolving those and refreshing and cleaning the project the described error magically disappeared. Special thanks to @howlger and @Naman for pointing me in the right direction.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.