Reputation: 929
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
Upvotes: 77
Views: 166056
Reputation: 13951
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:
"com/sun/xml/internal/**"
.After adding this access rule, your project should build without these warning.
Upvotes: 131
Reputation: 11
In the eclipse environment where you execute your java programs, take the following steps:
Upvotes: 1
Reputation: 77
In Eclipse:
Project -> properties -> java Build Path -> libraries
Remove existing JRE System Library, then Add Library -> JRE System library -> next -> ok
Error will be removed.
Upvotes: 8
Reputation: 151
i've solved this issue with these steps: expand your project, right click "JRE System Library" > Properties > choose 3rd option "Workspace default JRE" > OK . Hope it help you too
Upvotes: 15
Reputation: 2642
I'm responding to this question because I had a different way of fixing this problem than the other answers had. I had this problem when I refactored the name of the plugins that I was exporting. Eventually I had to make sure to fix/change the following.
This worked for me, but your mileage may vary.
Upvotes: 0
Reputation: 11107
I had the same problem when my plugin was depending on another project, which exported some packages in its manifest file. Instead of changing access rules, I have managed to solve the problem by adding the required packages into its Export-Package section. This makes the packages legally visible. Eclipse actually provides this fix on the "Access restriction" error marker.
Upvotes: 5
Reputation: 1
Go to Buildpath
Remove Existing JRE and add new JRE library which contain Jdk1.6 and finish Now clean all project and build again
I think this way you can resolved your error
Upvotes: -2
Reputation: 854
Excellent answer already provide onsite here.
See the summary below:
Upvotes: 79
Reputation: 419
Not a true solution, but everywhere I looked the solution suggested was to simply tell Eclipse that those aren't errors. You can change it by going to Properties --> Java Compiler --> Errors Warnings --> Deprecated and restrited APIs --> Forbidden reference (acess rule), Change it from Error to Warning or Ignore.
Upvotes: 41