hypercube
hypercube

Reputation: 1118

Eclipse 3.5.1 Compiler Error :The type OutputFormat is not accessible due to restriction on required library ../rt.jar

This error is weird and i cannot make much sense of it. I've installed EclipseRCP 3.5.1, Java SE 1.6 update 16 and switched to SWT 3.5. I've created a new project, set up the dependencies and tried to compile. When trying to import, use the following:

import com.sun.org.apache.xml.internal.serialize.OutputFormat;
import com.sun.org.apache.xml.internal.serialize.XMLSerializer;

i get the error :

Access restriction: The type XMLSerializer is not accessible due to restriction on required library C:\Program Files\Java\jre6\lib\rt.jar.

I've already google it, read some responses here..and the problem is still there. The funny thing is that if i use the previous EclipseRCP (Version: 3.4.2), this problem never occurs. The 3.4.2 version uses the same JRE version, and i've just tested the SWT version. Works fine. I guess the problem relies in some plugin of the new IDE. Any ideas?

P.S. I have found this article. But i don't like or want to change the code if i don't have to. What is the source of the problem first, and the solution will follow..

Upvotes: 6

Views: 17188

Answers (3)

wmjasonward
wmjasonward

Reputation: 21

I'm posting to this old thread just for reference for anyone who comes across this in the future.

I had the same problem but it was caused because I had my compiler compliance level set to 1.5 while using the 1.6 compiler. All the goodies that are included in 1.6 (like javax.activation, and some of the xml capabilities mentioned above) will be "restricted" by the 1.6 compiler if the compliance level is set lower than 1.6. I just had to add the appropriate libraries (e.g. activation.jar) to get rid of the issue in my case.

Upvotes: 1

David Moles
David Moles

Reputation: 51123

Just a note for anyone who runs across a similar problem and can't seem to get the Eclipse setting to work (e.g. me just now): check that "Forbidden reference" isn't set to "Error" in the project-specific settings.

Upvotes: 1

jarnbjo
jarnbjo

Reputation: 34313

The default configuration of the Eclipse compiler is too restrictive. You can loosen it up by opening the preferences for Java -> Compiler -> Errors/Warnings and under "Deprecated and restricted API" change the setting of "Forbidden reference (access rules)" from error to warning or ignore.

A question however is if you really want to use the classes in the com.sun.-package, since you are not guaranteed that these will be available in a VM from a different vendor or a newer VM from Sun.

Upvotes: 10

Related Questions