开发者

Eclipse with JSR 250 (annotation) yields "Access Restriction" errors

开发者 https://www.devze.com 2022-12-22 02:55 出处:网络
Hopefully someone has come across this before. I\'m running Spring STS 2.3.0 and when attempting to use the @Resource annotation from javax.annotations.Resource I get \"Access restriction: The type Re

Hopefully someone has come across this before. I'm running Spring STS 2.3.0 and when attempting to use the @Resource annotation from javax.annotations.Resource I get "Access restriction: The type Resource is not accessible due to restricti开发者_C百科on on required library". I'm using the JDK 6u18.

I've tried changing the JDK Compliance to 1.5 and 1.6 and both yield the same error.

Cheers, -Ed


This worked for me: Change eclipse (STS) project build path | Libraries tab | select JRE System Library [J2SE-1.4] | Edit button | change from Execution Environment radio tab which says J2SE 1.4 (jdk1.6.0_21) to Workspace default JRE (jdk1.6.0_21).


If you are using a Plug-in Project instead of a regular Java project, try setting

Bundle-RequiredExecutionEnvironment: JavaSE-1.6

in your manifest.mf. (And after changing it, you may need to Right click on the project and do PDE Tools -> Update Classpath


Thank you for your answer. Worked for me too.

Original Issue was: Access restriction warning showing upon using @Resource.

Steps taken to solve the issue: Build Path ->Configure build Path->libraries->select JRE System library->Edit-> select workspace default.


You might be able to change that configured compiler error to a warning or ignored, in the deprecated and restricted API section: Forbidden reference (access rules).


Eclipse should tell you what library (say, X) it's having an issue with. Something like this is happening:

  • Spring STS has a dependency on version V1 of library X.
  • Something else also has a dependency on version V2 (where V1 != V2) of library X.

Now you have a transitive dependency on the same library, but two different versions are in your classpath. That's not allowed. The solution is to remove things from your classpath and instead add specific libraries to your Eclipse build path.


You can open .classpath file and use

<\classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/
        org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>

instead.

0

精彩评论

暂无评论...
验证码 换一张
取 消