简体   繁体   English

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

[英]Access restriction on jdk1.7/jre/lib/rt.jar

hi folks I faced a very strange while creating my JAXB parser. 大家好,我在创建JAXB解析器时遇到了一个非常奇怪的问题。 When i tried to generate JAXB classes from eclipse then in one class it shows a very Strange error which is 当我试图从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

this is my 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 {

AND HERE ON THIS LINE I AM GETTING THE ERROR MESSAGE 在这条线上,我正在收到错误消息

private final static QName _ExpenseReport_QNAME = new QName("", "expenseReport"); 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);
    }

}

This problem occurs when you class path is referring to JRE instead of the JDK in which the Project is open into , do one thing go to 当您的类路径引用JRE而不是项目打开的JDK时,会出现此问题,请执行一项操作

Build Path > Libraries 构建路径>库

Remove the Runtime that is included and add the jdk runtime , it should solve your problem now. 删除包含的运行时并添加jdk运行时,它应该现在解决您的问题。

I got the next error: Access restriction: 我收到了下一个错误:访问限制:

The type XmlRegistry is not accessible due to restriction on required library C:\\Program Files (x86)\\Java\\jre7\\lib\\rt.jar 由于对所需库C:\\ Program Files(x86)\\ Java \\ jre7 \\ lib \\ rt.jar的限制,无法访问XmlRegistry类型

This is the way that I fixed the same problem that I had: 这是我修复我遇到的同样问题的方式:

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. 

The default worked for me. 默认对我有用。

Just remove and re-add the same JRE system library. 只需删除并重新添加相同的JRE系统库即可。

Note: Make sure to click 'OK' and close the dialog for both while removing and re-adding. 注意:确保在删除和重新添加时单击“确定”并关闭两者的对话框。

This situation can be solved as follows: 这种情况可以解决如下:

1 - Goto to the Java Compiler section of the Project Properties dialog and then Errors and Warnings. 1 - 转到Project Properties对话框的Java Compiler部分,然后转到Errors and Warnings。 2 - Check Enable project specific settings. 2 - 选中启用项目特定设置。 3 - Inside Deprecated and restricted API change the Forbidden reference (acess rule) to Warning or Ignore. 3 - 内部不推荐使用和受限制的API将禁止参考(访问规则)更改为警告或忽略。

4 - Please don't forget me in your pray 4 - 请不要忘记我的祈祷

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM