views:

2395

answers:

4

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..

+1  A: 

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.

jarnbjo
Yes, i am aware of the eclipse setting to work around the problem, but the same setting was in the older RCP version, and i didn't have the problem. I never heard that before..so, why is that package com.sun. even exist, if his use is not recommended??
Hypercube
The purpose of the imports was to read/write XML files, as it is my understanding that JDK1.6 has XML parsers built in. Are u suggesting that it cant be done, because com.sun.* shouldn't be used?
Hypercube
It is used internally by the public APIs, probably JAXB or something. If you need the classes directly, you should instead add Apache Xerces-J as a library and use the classes org.apache.xml.serialize.OutputFormat and org.apache.xml.serialize.XMLSerializer instead.
jarnbjo
Oh nooo..another import :-(. I was trying to avoid that..ah well..so, this is final? Bottom line is that, using Java API, one cannot parse XML files?
Hypercube
Of course you can, but you have to use the public APIs in e.g. javax.xml and not the internals of a specific VM implementation, which you are just seeing, will cause problems if you make minor changes to your setup, e.g. upgrading to a newer VM version.
jarnbjo
OK, another lesson learned, never use the private API. I had no idea :-). Thanks for your answer, question resolved.
Hypercube
+1  A: 

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.

David Moles
+1  A: 

Why don't the Eclipse developers put in all the information to set up Eclipse-3.5.1 in the README file just like all other software distributions?

I am using Ubuntu 8.04 (Hardy).

The installation complains that there is no ANT build!

nachikethas
A: 

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.

wmjasonward