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:

5
  • the error is from Eclipse compiler or Maven? Commented Aug 8, 2019 at 13:54
  • stackoverflow.com/questions/52913597/… Commented Aug 8, 2019 at 14:00
  • 1
    I'm not able to reproduce this issue in Eclipse 2019-06 (4.12). Which version do you use? Commented Aug 8, 2019 at 14:33
  • yep, error occurs in Eclipse 2019-06. Are there fixes already available? Commented Aug 9, 2019 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. Commented Aug 10, 2019 at 16:05

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.