jdk1.7 / jre / lib / rt.jar的访问限制

大家好,我在创建JAXB解析器时遇到了一个非常奇怪的问题。 当我试图从eclipse生成JAXB类时,在一个类中它显示了一个非常奇怪的错误

Access restriction: The type QName is not accessible due to restriction on required library /usr/lib/jvm/jdk1.7.0_02/jre/lib/rt.jar 

这是我的class级

 package generated; import javax.xml.bind.JAXBElement; import javax.xml.bind.annotation.XmlElementDecl; import javax.xml.bind.annotation.XmlRegistry; //import javax.xml.namespace.QName; import javax.xml.namespace.*; @XmlRegistry public class ObjectFactory { 

在这条线上,我正在收到错误消息

private final static QName _ExpenseReport_QNAME = new QName(“”,“expenseReport”);

  /** * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: generated * */ public ObjectFactory() { } /** * Create an instance of {@link ExpenseT } * */ public ExpenseT createExpenseT() { return new ExpenseT(); } /** * Create an instance of {@link UserT } * */ public UserT createUserT() { return new UserT(); } /** * Create an instance of {@link ItemT } * */ public ItemT createItemT() { return new ItemT(); } /** * Create an instance of {@link ItemListT } * */ public ItemListT createItemListT() { return new ItemListT(); } /** * Create an instance of {@link JAXBElement }{@code }} * */ @XmlElementDecl(namespace = "", name = "expenseReport") public JAXBElement createExpenseReport(ExpenseT value) { return new JAXBElement(_ExpenseReport_QNAME, ExpenseT.class, null, value); } } 

当您的类路径引用JRE而不是项目打开的JDK时,会出现此问题,请执行一项操作

构建路径>库

删除包含的运行时并添加jdk运行时,它应该现在解决您的问题。

我收到了下一个错误:访问限制:

由于对所需库C:\ Program Files(x86)\ Java \ jre7 \ lib \ rt.jar的限制,无法访问XmlRegistry类型

这就是我修复我遇到的同样问题的方法:

 1.Go to the Build Path settings in the project properties. (Right click on your application, then in the popout window you will see 'Build Path', slide right and click on 'Configure Build Path...') 2.Remove the JRE System Library 3.Add it back; Select "Add Library" and select the JRE System Library. 

默认对我有用。

只需删除并重新添加相同的JRE系统库即可。

注意:确保在删除和重新添加时单击“确定”并关闭两者的对话框。

这种情况可以解决如下:

1 – 转到Project Properties对话框的Java Compiler部分,然后转到Errors and Warnings。 2 – 选中启用项目特定设置。 3 – 内部不推荐使用和受限制的API将禁止引用(访问规则)更改为警告或忽略。

4 – 请不要忘记我的祈祷