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

kha*_*han 18 java java-ee java-7

大家好,我在创建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
Run Code Online (Sandbox Code Playgroud)

这是我的班级

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 {
Run Code Online (Sandbox Code Playgroud)

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

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

}
Run Code Online (Sandbox Code Playgroud)

Aka*_*dav 39

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

构建路径>库

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

  • 我在使用maven-jaxb2-plugin和Maven/JAXB/m2e/Eclipse时遇到了这个问题.Eclipse使用的是Java 1.5,所以我添加了maven-compiler-plugin来将我的源版本和目标版本设置为1.7并且事情很好. (6认同)

S. *_*yol 12

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

由于对所需库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. 
Run Code Online (Sandbox Code Playgroud)

默认对我有用.