[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. Thank you very much
    god bless you

    ReplyDelete
  38. 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
  39. 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
  40. Thanks...It worked !!!! :)

    ReplyDelete
  41. thank you very much

    ReplyDelete
  42. excellent, thanx :)

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

    ReplyDelete
  44. thanks for the post, works perfect!

    ReplyDelete
  45. 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
  46. Thanks a lot. Your comments helped me.

    ReplyDelete
  47. It really helped me. Thanks.

    ReplyDelete
  48. awesome thanks.

    ReplyDelete
  49. Man...

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

    xD

    ReplyDelete
  50. Proposed solution works correctly.
    Hal

    ReplyDelete
  51. Perfect. Thank you so much.

    ReplyDelete
  52. thanks, very helpful

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

    Thanks Kamal !!!

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

    -- Ravi & Jayesh

    ReplyDelete
  55. 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
  56. Thank you!!! You solved my problem!! thanks again!!

    ReplyDelete
  57. Excellent solution for my confusion

    Thanking you

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

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

    ReplyDelete
  60. 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
  61. Cool!
    I was stucked!

    It saved me!

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

    ReplyDelete
  63. Excelent !!!!

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

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

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

    Thanks .

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

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

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

    ReplyDelete
  69. Thanks for the post

    ReplyDelete
  70. thanks...........

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

    ReplyDelete
  72. Still relevant. Thanks.

    ReplyDelete
  73. Answer No. 42 helped me.

    ReplyDelete
  74. excellent, merci

    ReplyDelete
  75. THANK YOU VERY MUCH FROM SPAIN.

    ReplyDelete
  76. Great, Fantastic, Thank you so much

    ReplyDelete
  77. Great..It worked

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

    ReplyDelete
  79. 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
  80. Thanks a ton.....!! U saved my time..!!

    ReplyDelete
  81. Thanks, your solution is good

    ReplyDelete
  82. thank you very much.

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

    ReplyDelete
  84. Thank You for the help!!

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

    ReplyDelete
  86. 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
  87. 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
  88. This is exactly what I searched for, thanks...
    u rock

    ReplyDelete
  89. THANK U VERY MUCH

    ReplyDelete
  90. Thanks for the help mate.

    ReplyDelete
  91. That was so helpful

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

    ReplyDelete
  93. Thanks! This was driving me nuts.

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

    ReplyDelete
  95. Thanks a lot for this post.

    ReplyDelete
  96. 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
  97. Thanks it helped me and
    saved my time

    ReplyDelete
  98. 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
  99. thanks, good info.

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

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

    Cristiano

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

    ReplyDelete
  103. You rock, this was driving me crazy

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

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

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

    ReplyDelete
  107. thanku very very much

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

    ReplyDelete
  109. cool...Thx!
    Joel Design

    ReplyDelete
  110. Thank you very much...............................

    ReplyDelete
  111. Thank you very much....

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

    ReplyDelete
  113. 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
  114. But how it works in fedora in eclipse

    ReplyDelete
  115. thanks good job

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

    ReplyDelete

Post Top Ad

Responsive Ads Here