Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access restriction: Is not accessible due to restriction on required library ..\jre\lib\rt.jar

I am trying to modify some legacy code from while back and getting the following kind of errors:

Access restriction: The method create(JAXBRIContext, Object) from the type Headers is not accessible due to restriction on required library ..\jre\lib\rt.jar

for these import statements:

import com.sun.xml.internal.bind.api.JAXBRIContext; import com.sun.xml.internal.ws.api.message.Header; import com.sun.xml.internal.ws.api.message.Headers; import com.sun.xml.internal.ws.developer.WSBindingProvider; 

Been searching what this might mean and how to fix it, however not been able to find a clear answer. Some posts seem to suggest that I have some JARs included that implement classes that are now available as part of the core java distribution, but as far as I can see none of the JARs I include contain different/older versions of the above classes.

Anyone able to tell me what this error is all about and how I might go about fixing this?

Thanks for your help already in advance,

Olli

like image 393
user567602 Avatar asked Feb 13 '12 19:02

user567602


People also ask

What is RT jar file in Java?

rt. jar contains all of the compiled class files for the base Java Runtime environment, as well as the bootstrap classes, which are the run time classes that comprise the Java platform core API.


Video Answer


1 Answers

I ran into something similar, I think that the cause of the warning is Eclipse trying to discourage you from using the internal com.sun packages that are installed as part of your workspace JRE but which are not part of the public Java API.

As Justin says in his answer, changing your compiler settings can hide the warning. A more fine-grained approach is to modify your build path to explicitly allow access to the package in question:

  1. Open the Libraries tab of the Java Build Path project property window.
  2. Expand the JRE System Library entry.
  3. Select "Access rules" and hit the Edit button.
  4. Click the Add button in the resulting dialog.
  5. For the new access rule, set the resolution to Accessible and the pattern to "com/sun/xml/internal/**".

After adding this access rule, your project should build without these warning.

like image 125
Alex Avatar answered Sep 27 '22 23:09

Alex