3

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:

Naman
  • 27,789
  • 26
  • 218
  • 353
Jörg
  • 822
  • 1
  • 10
  • 13
  • the error is from Eclipse compiler or Maven? – Naman Aug 08 '19 at 13:54
  • https://stackoverflow.com/questions/52913597/springboot-org-hibernate-mappingexception-could-not-get-constructor-for-org-hi – Ng Sharma Aug 08 '19 at 14:00
  • 1
    I'm not able to reproduce this issue in Eclipse 2019-06 (4.12). Which version do you use? – howlger Aug 08 '19 at 14:33
  • yep, error occurs in Eclipse 2019-06. Are there fixes already available? – Jörg Aug 09 '19 at 19:39
  • It seems as if the Java module support in Eclipse 2019-06 is rather buggy. So if you have some compile error in your module then you also get wired other phantom errors as a side effect. – Jörg Aug 10 '19 at 16:05

1 Answers1

0

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.

Jörg
  • 822
  • 1
  • 10
  • 13