java Eclipse 3.5.1 编译器错误:由于所需库 ../rt.jar 的限制,无法访问类型 OutputFormat
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1517619/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Eclipse 3.5.1 Compiler Error :The type OutputFormat is not accessible due to restriction on required library ../rt.jar
提问by hypercube
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:
这个错误很奇怪,我无法理解。我已经安装了 EclipseRCP 3.5.1、Java SE 1.6 update 16 并切换到 SWT 3.5。我创建了一个新项目,设置了依赖项并尝试编译。尝试导入时,请使用以下命令:
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?
我已经用谷歌搜索过了,在这里阅读了一些回复……但问题仍然存在。有趣的是,如果我使用以前的 EclipseRCP(版本:3.4.2),这个问题就不会发生。3.4.2版本使用相同的JRE版本,我刚刚测试了SWT版本。工作正常。我猜这个问题依赖于新 IDE 的一些插件。有任何想法吗?
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..
PS我找到了这篇文章。但如果我不需要,我不喜欢或不想更改代码。首先问题的根源是什么,然后解决方案。
回答by jarnbjo
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.
Eclipse 编译器的默认配置过于严格。您可以通过打开 Java -> Compiler -> Errors/Warnings 的首选项并在“已弃用和受限 API”下将“禁止引用(访问规则)”的设置从错误更改为警告或忽略来放松它。
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.
然而,一个问题是您是否真的想使用 com.sun.-package 中的类,因为您不能保证这些类在来自不同供应商的 VM 或来自 Sun 的更新的 VM 中可用。
回答by David Moles
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-specificsettings.
对于遇到类似问题并且似乎无法使 Eclipse 设置正常工作的任何人(例如我刚才),请注意:检查项目特定设置中的“禁止引用”未设置为“错误” .
回答by wmjasonward
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.
我遇到了同样的问题,但这是因为我在使用 1.6 编译器时将编译器合规性级别设置为 1.5。javax.activation如果合规性级别设置为低于 1.6 ,则 1.6 中包含的所有优点(如,以及上面提到的一些 xml 功能)将被 1.6 编译器“限制”。我只需要添加适当的库(例如activation.jar)来解决我的问题。

