18

hi folks I faced a very strange while creating my JAXB parser. When i tried to generate JAXB classes from eclipse then in one class it shows a very Strange error which is

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");

    /**
     * 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);
    }

}
khan
  • 2,664
  • 8
  • 38
  • 64

4 Answers4

39

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

Build Path > Libraries

Remove the Runtime that is included and add the jdk runtime , it should solve your problem now.

catch23
  • 17,519
  • 42
  • 144
  • 217
Akash Yadav
  • 2,411
  • 20
  • 32
  • 6
    I was getting this problem while using maven-jaxb2-plugin with Maven/JAXB/m2e/Eclipse. Eclipse was using Java 1.5, so I added the maven-compiler-plugin to set my source and target versions to 1.7 and things were good. – Nathaniel Waisbrot Dec 27 '12 at 17:04
  • I think that @NathanielWaisbrot is correct (at least in some cases). I had the same problem, but WAS using the JDK. Setting up the maven plugin for Java 1.7 rather than 1.5 fixed things for me as well. – jedison Aug 08 '14 at 14:35
  • In java 8, I got same error while instantiating com.sun.security.auth.module.NTSystem NTSystem = new com.sun.security.auth.module.NTSystem(); Changing java compliance to 1.5 fixed the issue for me. – Abhishek Singh Jul 30 '17 at 21:02
12

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

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.

S. Mayol
  • 2,565
  • 2
  • 27
  • 34
2

Just remove and re-add the same JRE system library.

Note: Make sure to click 'OK' and close the dialog for both while removing and re-adding.

Dinesh Kumar
  • 2,838
  • 1
  • 16
  • 18
0

This situation can be solved as follows:

1 - Goto to the Java Compiler section of the Project Properties dialog and then Errors and Warnings. 2 - Check Enable project specific settings. 3 - Inside Deprecated and restricted API change the Forbidden reference (acess rule) to Warning or Ignore.

4 - Please don't forget me in your pray