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

2022-09-02 19:21:39

嗨,伙计们,我在创建我的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

这是我的班级

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 {

在这一行上,我收到错误消息

私有最终静态 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 <}{@link ExpenseT }{@code >}}
     * 
     */
    @XmlElementDecl(namespace = "", name = "expenseReport")
    public JAXBElement<ExpenseT> createExpenseReport(ExpenseT value) {
        return new JAXBElement<ExpenseT>(_ExpenseReport_QNAME, ExpenseT.class, null, value);
    }

}

答案 1

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

构建路径>库

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


答案 2

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

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

这就是我解决与我遇到的相同问题的方法:

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. 

默认值对我有用。


推荐