[java] Access restriction on class due to restriction on required library rt.jar?

I'm attempting to compile Java 1.4 code that was created by IBM's WSDL2Java on Java5 without recreating the stubs and saw this error in Eclipse.
I'm under the assumption that the stubs generated should just compile as long as the runtime jars are available (they are).

Access restriction: The type QName is not accessible due to restriction on required library C:\Program Files\Java\jdk1.5.0_16\jre\lib\rt.jar

The full class name is javax.xml.namespace.QName

What exactly is going on here? Is this a case where I am trying to refactor a pig from sausage? Am I better off recreating the stubs?

This question is related to java eclipse wsdl stub wsdl2java

The answer is


Sorry for updating an old POST. I got the reported problem and I solved it as said below.

Assuming you are using Eclipse + m2e maven plugin, if you get this access restriction error, right click on the project/module in which you have the error --> Properties --> Build Path --> Library --> Replace JDK/JRE to the one that is used in eclipse workspace.

I followed the above steps and the issue is resolved.


I just had this problem too. Apparently I had set the JRE to 1.5 instead of 1.6 in my build path.


Go to the Java Build Path in the project properties. Remove the existing JRE System Library Then Add it again i.e. Add Library-->JRE Lib--select jre--->Finish. Lastly select order and export tab select JRE Lib and move on top. That's it.


  • Go to the Build Path settings in the project properties. Windows -> Preferences -> Java Compiler
  • Remove the JRE System Library
  • Add another JRE with a "perfect match"
  • clean and build your project again. It worked for me.

My guess is that you are trying to replace a standard class which ships with Java 5 with one in a library you have.

This is not allowed under the terms of the license agreement, however AFAIK it wasn't enforced until Java 5.

I have seen this with QName before and I "fixed" it by removing the class from the jar I had.

EDIT http://www.manpagez.com/man/1/java/ notes for the option "-Xbootclasspath:"

"Applications that use this option for the purpose of overriding a class in rt.jar should not be deployed as doing so would contravene the Java 2 Runtime Environment binary code license."

The http://www.idt.mdh.se/rc/sumo/aJile/Uppackat/jre/LICENSE

"Java Technology Restrictions. You may not modify the Java Platform Interface ("JPI", identified as classes contained within the "java" package or any subpackages of the "java" package), by creating additional classes within the JPI or otherwise causing the addition to or modification of the classes in the JPI. In the event that you create an additional class and associated API(s) which (i) extends the functionality of the Java platform, and (ii) is exposed to third party software developers for the purpose of developing additional software which invokes such additional API, you must promptly publish broadly an accurate specification for such API for free use by all developers. You may not create, or authorize your licensees to create, additional classes, interfaces, or subpackages that are in any way identified as "java", "javax", "sun" or similar convention as specified by Sun in any naming convention designation."


I met the same problem. I found the answer in the website:http://www.17ext.com.
First,delete the JRE System Libraries. Then,import JRE System Libraries again.

I don't know why.However it fixed my problem,hope it can help you.


http://www.digizol.com/2008/09/eclipse-access-restriction-on-library.html worked best for me.

On Windows: Windows -> Preferences -> Java -> Compiler -> Errors/Warnings -> Deprecated and restricted API -> Forbidden reference (access rules): -> change to warning

On Mac OS X/Linux: Eclipse -> Preferences -> Java -> Compiler -> Errors/Warnings -> Deprecated and restricted API -> Forbidden reference (access rules): -> change to warning


In the case you are sure that you should be able to access given class, than this can mean you added several jars to your project containing classes with identical names (or paths) but different content and they are overshadowing each other (typically an old custom build jar contains built-in older version of a 3rd party library).

For example when you add a jar implementing:

a.b.c.d1
a.b.c.d2

but also an older version implementing only:

a.b.c.d1
(d2 is missing altogether or has restricted access)

Everything works fine in the code editor but fails during the compilation if the "old" library overshadows the new one - d2 suddenly turns out "missing or inaccessible" even when it is there.

The solution is a to check the order of compile-time libraries and make sure that the one with correct implementation goes first.


Adding a right JRE System through build path is the solution but your eclipse still may have the error. To solve that go to Java Build path --> Order and Export and move your JRE system library on the top. This has solved my problem.


In my case there was a mismatch between the build path JRE and installed JRE on execution environment. I moved into Project > Properties > Java compiler. There was a warning message at the bottom.

I clicked on the links 'Installed JRE', 'Execution environment', 'Java build path' and changed the JDK version to 1.7 and the warning disappeared.


I have been getting this error too, but my project is built on the command line using Maven and the tycho compiler (it's a set of OSGi plugins). After masses of sifting through people having the same problem but fixing it in Eclipse rather than on the command line, I found a message on the Tycho developer forum that answered my question, using configuration in pom.xml to ignore the compiler warning about the access restriction:

<plugin>
    <groupId>org.eclipse.tycho</groupId>
    <artifactId>tycho-compiler-plugin</artifactId>
    <version>${tycho.version}</version>
    <configuration>
        <compilerArgument>-warn:+discouraged,forbidden</compilerArgument>
    </configuration>
</plugin>

More information can be found in the Tycho FAQ. This took me AGES to work out, so I figured I would assist anyone else trying to fix these access restriction errors from the command line by posting this answer.


for me this how I solve it:

  • go to the build path of the current project

under Libraries

  • select the "JRE System Library [jdk1.8xxx]"
  • click edit
  • and select either "Workspace default JRE(jdk1.8xx)" OR Alternate JRE
  • Click finish
  • Click OK

enter image description here

Note: make sure that in Eclipse / Preferences (NOT the project) / Java / Installed JRE ,that the jdk points to the JDK folder not the JRE C:\Program Files\Java\jdk1.8.0_74

enter image description here


In addition to Nels Beckman's solution, I have the following tips:

Under Configure Build Path, I had to rearrange the order of my entries under Order and Export.

Additionally, as an Eclipse PDE developer, I needed to rearrange the order of my dependencies in my MANIFEST.MF, adding the problematic package as first on the list.

Playing with these dials, along with running Project > Clean in between, I was able to resolve these warnings.


Just change the order of build path libraries of your project. Right click on project>Build Path> Configure Build Path>Select Order and Export(Tab)>Change the order of the entries. I hope moving the "JRE System library" to the bottom will work. It worked so for me. Easy and simple....!!!


Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to eclipse

How do I get the command-line for an Eclipse run configuration? My eclipse won't open, i download the bundle pack it keeps saying error log strange error in my Animation Drawable How to uninstall Eclipse? How to resolve Unable to load authentication plugin 'caching_sha2_password' issue Class has been compiled by a more recent version of the Java Environment Eclipse No tests found using JUnit 5 caused by NoClassDefFoundError for LauncherFactory How to downgrade Java from 9 to 8 on a MACOS. Eclipse is not running with Java 9 "The POM for ... is missing, no dependency information available" even though it exists in Maven Repository The origin server did not find a current representation for the target resource or is not willing to disclose that one exists. on deploying to tomcat

Examples related to wsdl

Generating Request/Response XML from a WSDL How to generate xsd from wsdl How do you convert WSDLs to Java classes using Eclipse? How to get the wsdl file from a webservice's URL JSON, REST, SOAP, WSDL, and SOA: How do they all link together Difference between a SOAP message and a WSDL? SOAP PHP fault parsing WSDL: failed to load external entity? How to do a SOAP wsdl web services call from the command line Importing xsd into wsdl SoapUI "failed to load url" error when loading WSDL

Examples related to stub

What does "to stub" mean in programming? java.net.ConnectException :connection timed out: connect? What's the difference between a mock & stub? Access restriction on class due to restriction on required library rt.jar?

Examples related to wsdl2java

Importing xsd into wsdl How to avoid the need to specify the WSDL location in a CXF or JAX-WS generated webservice client? Java Webservice Client (Best way) Access restriction on class due to restriction on required library rt.jar?