问题
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);
}
}
回答1:
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.
回答2:
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.
回答3:
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.
回答4:
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
来源:https://stackoverflow.com/questions/10428984/access-restriction-on-jdk1-7-jre-lib-rt-jar