views:

16100

answers:

6

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 created 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 classname 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?

+6  A: 

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."

Peter Lawrey
that's it. one of the jars in the path had the QName class in it. find . -name "*.jar" -print -exec unzip -t {} \; |grep "QName" found it.
sal
Could you provide a reference about not being allowed to replace classes which ship with Java? All I found in the licence agreement was restrictions related to distributing Java itself, not Java programs, but I didn't look for very long.
Adrian Mouat
+5  A: 

I met the same problem.I found the answer in the website:http://www.17ext.com. firt,delete the JRE System Libriaries. Then,import JRE System Libriaries again. I don't konw why.However i fixed my problom,hope it can help you

sanwanxian
this one worked for me, thanks!
nimcap
worked for me as well, thanks!
Ankur
This one fixed my problem as well.
Sbodd
+10  A: 

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

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

scommab
This might work, but it is not a proper solution. You need to understand why the access restriction existed in the first place. It will also hide all future cases of this, which may be more important!
Adrian Mouat
A: 

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

I did this worked.. but is this a permanent solution.. means what would happen when my code would run outside of eclipse

shekup
+4  A: 

There's another solution that also works. I found it on this forum:

  1. Go to the Build Path settings in the project properties.
  2. Remove the JRE System Library
  3. Add it back; Select "Add Library" and select the JRE System Library. The default worked for me.
Nels Beckman
+2  A: 
  • 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.
Mayur