问题

我试图编译由 IBM's WSDL2 创建的 Java 1.4 代码,但是在Eclipse中看到此错误。

Access restriction: The type QName is not accessible due to restriction on required library C:\Program Files\Java\jdk1.5.0_16\jre\lib\rt.jar 

完整的类名是javax.xml.namespace.QName

到底发生了什么?

这是我试图从香肠重构猪的情况吗?我最好重新创建 stub 吗?


#1 热门回答(1795 赞)

还有另一种解决方案也可以。

  • 转到项目属性中的 “Build Path ” 设置。
  • 删除 JRE lib
  • 重新添加它; 选择 "Add Library" and 选择  JRE System Library

这是有效的,因为您在不同的jar文件中有多个类。删除并重新添加JRE库将使正确的类成为第一个。如果您想要一个基本的解决方案,请确保使用相同的类排除jar文件。

对我来说,我有:javax.xml.soap.SOAPPart在三个不同的 Jar 里:axis-saaj-1.4.jarsaaj-api-1.3.jarrt.jar


#2 热门回答(111 赞)

http://www.digizol.com/2008/09/eclipse-access-restriction-on-library.html对我来说最好。

On Windows: Windows -> Preferences -> Java -> Compiler -> Errors/Warnings -> Deprecated and restricted API -> Forbidden reference (access rules): -> change to warning

On Mac OS X/Linux: Eclipse -> Preferences -> Java -> Compiler -> Errors/Warnings -> Deprecated and restricted API -> Forbidden reference (access rules): -> change to warning


#3 热门回答(66 赞)

我遇到了同样的问题。我在网站上找到了答案:http://www.17ext.com
首先,删除 JRE 系统库。然后,再次导入 JRE 系统库。

我不知道为什么。但它解决了我的问题,希望它能帮助你。


原文链接