[Eclipse] Access restriction: Class is not accessible due to restriction on required library - Digizol6

Post Top Ad

Responsive Ads Here

Post Top Ad

Responsive Ads Here

Tuesday, September 9, 2008

[Eclipse] Access restriction: Class is not accessible due to restriction on required library

"Access restriction: Class is not accessible due to restriction on required library"; error message may be shown while developing Java projects in Eclipse IDE. Error message is self-explanatory, some classes can not be loaded into the project since restriction rules are being imposed on those classes.

How to solve

This error message can be removed by changing a setting inside Eclipse IDE. Open up the dialog box shown below, using any of the following paths.
  • Windows -> Preferences -> Java -> Compiler -> Errors/Warnings
  • (Project) Properties -> Java Compiler -> Errors/Warnings
Locate the "Forbidden reference (access rules)" option under "Deprecated and restricted API" section in the dialog box. This option decides how to handle access rules defined inside Eclipse. By default it is set to "Error" which causes Eclipse to complain about references to any restricted classes. Choosing any other option (Warning or Ignore) will remove these error messages.

"Warning" or "Ignore" options will only hide the potential issue in the project, by allowing the project to use any classes ignoring predefined access rules. To completely resolve this issue, analyze the project and located the use of restricted classes and take necessary actions (either remove those references or access rules).

Related Articles

155 comments:

  1. This is exactly what I searched for, thanks.

    ReplyDelete
  2. thanks for your post. Solved my problem!

    ReplyDelete
  3. thanks for the post....solved my problem!!

    ReplyDelete
  4. Thanks for this, exactly what has been annoying me for for weeks.

    ReplyDelete
  5. thanks, this saved my time.

    ReplyDelete
  6. I don't understand what these restrictions are, but thanks for the tip - made my day.

    ReplyDelete
  7. Wow...I have been searching all over the place for this answer. Thanks for posting this.

    ReplyDelete
  8. Thanks a lot. It resolved my issue

    ReplyDelete
  9. Wonderful, this one was driving me crazy !

    ReplyDelete
  10. This post does not appear to provide a satisfactory solution to the problem, but merely explains how to make the warning go away. If you see the error "Access restriction: The method (name) from the type (class) is not accessible due to restriction on required project (project)" can be solved by 1) Right click on the project with the problem and select "properties"; 2) Select "Java Build Path"; 3) Expand "Plug-in Dependencies" and expand the project causing the problem; 4) Expand "Access rules" and modify them to ensure the referenced class is accessible.

    ReplyDelete
  11. Good.Quick and Neat help.........
    Thanks

    ReplyDelete
  12. The post by Anonymous on March 27, 2009 1:59AM does not solve the problem either. By modifying the Access Rules you are simply hiding the problem. The Access Rules are there for a reason and you need to fix the problem. If you don't, you are probably in violation of the Java license.

    ReplyDelete
  13. A BIG problem, with a SIMPLE solution.

    Thanks a lot.

    ReplyDelete
  14. I encountered this when creating a maven apache cxf prototype. The problem was not fixable by changing access rules for the library because these were not modifiable. The solution for me was to use a newer JDK or change the Order/Export (I think this is class loader order) so the Maven-supplied jaxb-api2.1.jar was used. The workspace Java 1.5 system library was not correctly exporting the javax.jws.* package. My approach was just to change the system library to a 1.6 one.

    ReplyDelete
  15. Brilliant, mate! Helped me too. Thanks!

    ReplyDelete
  16. The Anonymous of March 27, 2009 1:59 AM was right. The other way to do the same things is to use plugin editor and add there on Runtime page the project/package you want to get from the class with error. This will allow the package to export. But this solution makes sense only for those who works with several projects of their own (like in case of plug-ins development). In simple cases when the error doesn't say anything to you the suggested by Kamal way is possibly one you are looking for. And then don't mess with the restriction editing.

    ReplyDelete
  17. thansk for your help

    ReplyDelete
  18. Great. You save me! :)

    ReplyDelete
  19. Saved my precious time! Thanks!

    ReplyDelete
  20. The post by Mick (June 18, 2009 4:13 PM) solved my problem. thanks!
    My problem is "Access restriction to all class in /usr/java/zenith_jdk1.6.0_04/jre/lib/rt.jar".
    The solution for me was to change the (Project) Properties -> Order/Export (I think this is class loader order), I just moved the "JRE System Library [zenith_jdk1.6.0_04]" above others.

    ReplyDelete
  21. that was really helpful ...thanks a lot

    ReplyDelete
  22. THANK YOU!!!! SOOO MUCHHHH!!! YOU SAVE MY LIFE!!!

    ReplyDelete
  23. Still useful a whole year later. Thanks!

    ReplyDelete
  24. Thanks Dude .. I was bugged with the problem and wasted a lot of time on it .. went through a number of posts .. but finally this is what I was looking for ..
    Thnx once again

    ReplyDelete
  25. I'm using Eclipse with JMF's just been installed. I don't like to hide this error. I'd like to resolve it completely. Anyone helps me?

    ReplyDelete
  26. Obrigado.
    esta foi uma exelente ajuda.

    ReplyDelete
  27. Thanks for this post ;-)

    ReplyDelete
  28. My problem was solved when I put the JDK at the end of the "Order and Export".

    ReplyDelete
  29. thanks you help me solve this problem

    ReplyDelete
  30. Excellent, You save me a lot of time.

    ReplyDelete
  31. "My problem was solved when I put the JDK at the end of the "Order and Export".
    Totally, its really strange why eclipse fails to load classes that are below the JRE.

    ReplyDelete
  32. Here another fix this issue:
    I get the "Access restriction: The type xxxxx is not accessible due to restriction on required project.." compilation error ¶

    * If you just created a new service interface, then you probably forgot to add it in the "Exported Packages" of the .services project.
    * If you encounter rt.jar Restrictions (on com.sun... classes for example) - these seem to be built-in Restrictions of Eclipse 3.3/OSGi and indicate you are doing something deprecated in OSGi. Try to do it "the right way".

    ReplyDelete
  33. Thanks for post, it helped, but I would like to fix this problem like Emerald214 (October 12, 2009 11:10 AM)
    "I'm using Eclipse with JMF's just been installed. I don't like to hide this error. I'd like to resolve it completely. Anyone helps me? ".

    What do I need to do then? I'm using JMF too...

    ReplyDelete
  34. Thank u very much..this was actually am looking for,,,

    ReplyDelete
  35. Although this doesn't tell me why I got this error, it does tell me how to successfully ignore it until I have time to figure it out, which is great. Thanks for saving me a lot of time.

    ReplyDelete
  36. I still had the problem. Not getting solved. Could you please help me with detailed steps.
    Access restriction: The type Vector3d is not accessible due to restriction on required library C:\Program Files (x86)\Java\jre1.5.0_06\lib\ext\vecmath.jar

    ReplyDelete
  37. Thanks Mike for the direction.

    This is how I did in Eclipse 3.5:
    Right Click on Project and select Properties -> Java Build Path -> Libraries (Tab)

    expand the rt.jar and see where you have forbidden access (**/*) in my case.

    Now edit "access rules" -> Add -> Resolution = "Accessible" and Rule Pattern = **/*

    Click OK and you are done.

    ReplyDelete
  38. This is exactly the kind of article I like to find when I have a problem. I's short, accurate, and does the job -- thanks.

    ReplyDelete
  39. Thanks...It worked !!!! :)

    ReplyDelete
  40. thank you very much

    ReplyDelete
  41. As a newbie in java, it took to much time to find this simple solution.
    Thank you very much ;)

    ReplyDelete
  42. thanks for the post, works perfect!

    ReplyDelete
  43. God bless you, I was desperatly. My message said "Access restriction: TYPE is not accessible due to restriction on required library" instead of class but worked for me too.

    Thanks a lot

    ReplyDelete
  44. Thanks a lot. Your comments helped me.

    ReplyDelete
  45. It really helped me. Thanks.

    ReplyDelete
  46. Man...

    Thank you very much. You've saved my soul!

    xD

    ReplyDelete
  47. Proposed solution works correctly.
    Hal

    ReplyDelete
  48. Perfect. Thank you so much.

    ReplyDelete
  49. thanks, very helpful

    ReplyDelete
  50. Erval Goncalves JuniorJuly 18, 2010 at 9:34 PM

    Thanks Kamal !!!

    ReplyDelete
  51. Thank you very much for this tip. We encountered this problem while using Eclipse Helios IDE.

    -- Ravi & Jayesh

    ReplyDelete
  52. Thanks !

    Had the same problem (with maven) :
    Access restriction: The type XXX is not accessible due to restriction on required library C:\bin\dvlp\java\jdk1.6.0_07\jre\lib\rt.jar

    ReplyDelete
  53. Thank you!!! You solved my problem!! thanks again!!

    ReplyDelete
  54. Excellent solution for my confusion

    Thanking you

    ReplyDelete
  55. awesome. I was almost getting really angry with this problem. I tried to get access to jai-core.jar. Thanks!

    ReplyDelete
  56. thanks very much!!! it's just great!

    ReplyDelete
  57. Thank you very much, this is the only resource I could find on the internet which told me how to deal with problem

    Thank you very much

    ReplyDelete
  58. Cool!
    I was stucked!

    It saved me!

    ReplyDelete
  59. thanks buddy, this is the correct solution
    ELio

    ReplyDelete
  60. Excelent !!!!

    Does anybody Know how to perform that configuration on Windows Registry ?
    ( or at some file ? )

    ReplyDelete
  61. This is exactly what I searched too !! Thank you.

    ReplyDelete
  62. Simple solution. I was looking for this for many days.

    Thanks .

    ReplyDelete
  63. Thanks for all the comments...
    For my case: I just recreated the project and everything is working...

    ReplyDelete
  64. Many thanks Kamal. You have just made my day with this....

    ReplyDelete
  65. It's great. I was looking into the read/write permissions for the lib. Thanks for the post and saved lot of time.

    ReplyDelete
  66. Thanks for posting. Helped me a lot!

    ReplyDelete
  67. Still relevant. Thanks.

    ReplyDelete
  68. Answer No. 42 helped me.

    ReplyDelete
  69. THANK YOU VERY MUCH FROM SPAIN.

    ReplyDelete
  70. Great, Fantastic, Thank you so much

    ReplyDelete
  71. Thanks, Its really nice answer.....

    ReplyDelete
  72. Another way of solving this issue is to delete JRE and install another JRE and change the JRE for the workspace, it will start working. :)

    Tkish

    ReplyDelete
  73. Thanks a ton.....!! U saved my time..!!

    ReplyDelete
  74. Thanks, your solution is good

    ReplyDelete
  75. thank you very much.

    ReplyDelete
  76. Thanks a lot.
    This is exactly what I was looking for.

    ReplyDelete
  77. Thank You for the help!!

    ReplyDelete
  78. Finally, two days looking for a solution. Thanks

    ReplyDelete
  79. Thank you very much for the informations;
    My code si working but it keep on give me warnings! I can't modify my access rules on jmf.jar library.

    ReplyDelete
  80. Thank you for this article; now I can run my code even if I still have some wornings because I can't edit access rules on jmf.rar
    If I'll be able to modify this permissions I'll give you news :)

    ReplyDelete
  81. This is exactly what I searched for, thanks...
    u rock

    ReplyDelete
  82. Thanks for the help mate.

    ReplyDelete
  83. Thanks a lot, this helped to resolve my problem

    ReplyDelete
  84. Thanks! This was driving me nuts.

    ReplyDelete
  85. I think the comment number 41 is the best solution to this problem....

    ReplyDelete
  86. Thanks a lot for this post.

    ReplyDelete
  87. Make sure you never "export" de plugin dependencies.

    So go over all required plugins and check that they are not exporting their plugin dependencies.

    ReplyDelete
  88. Thanks it helped me and
    saved my time

    ReplyDelete
  89. My JUnit tests today were giving me this error all day. I wasn't finding answers and hours have gone by.

    Reading your solution left me questioning if this was actually a non-issue. Upon following your guide I was able to compile the code and tests were acting as expected. I will continue to look into this warning and thank you for your post!

    ReplyDelete
  90. Thanks man.........It really helped me. Keep it up.

    ReplyDelete
  91. Today is 2014... and your post still helps people! Thank you, mate!

    Cristiano

    ReplyDelete
  92. This helped me a lot! Thanks :)

    ReplyDelete
  93. You rock, this was driving me crazy

    ReplyDelete
  94. Thanks Dude.
    it really saved lot of time.

    ReplyDelete
  95. Thanks, It resolved my issue...

    ReplyDelete
  96. thanks for your post.this saved my time,and solved my problem.

    ReplyDelete
  97. thanku very very much

    ReplyDelete
  98. Sir Thank you very much....Salute to you Sir....

    ReplyDelete
  99. cool...Thx!
    Joel Design

    ReplyDelete
  100. Thank you very much...............................

    ReplyDelete
  101. Thank you very much....

    ReplyDelete
  102. Çok teşekkür ederim
    :):)

    ReplyDelete
  103. please help me i'm only one who can't solve this probléme i have this probléme

    Exception in thread "main" java.lang.Error: Unresolved compilation problem:
    The method JToolBar() is undefined for the type InterfaceGraphique







    ReplyDelete
  104. thank you for the post . i solve the problem

    ReplyDelete

Post Top Ad

Responsive Ads Here