由于所需库 rt.jar 的限制而对类进行访问限制?

发布于 2024-07-19 08:18:04 字数 463 浏览 7 评论 0 原文

我正在尝试编译由 IBM WSDL2JavaJava5 上创建的 Java 1.4 代码,而无需重新创建存根和在 Eclipse 中看到此错误。
我假设只要运行时 jars 可用(它们是可用的),生成的存根就应该编译。

访问限制:由于所需库的限制,无法访问类型 QName C:\Program Files\Java\jdk1.5.0_16\jre\lib\rt.jar

完整类名为 javax.xml.namespace.QName

这里到底发生了什么? 这是我试图用香肠重构猪的情况吗? 我重新创建存根会更好吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(15

菩提树下叶撕阳。 2024-07-26 08:18:04

还有另一种解决方案也有效。

  1. 转到项目属性中的构建路径设置。
  2. 删除JRE系统库
  3. 将其添加回来; 选择“添加库”并选择 JRE 系统库。 默认对我有用。

这是可行的,因为不同的 jar 文件中有多个类。 删除并重新添加 JRE 库将使正确的类成为第一个。
如果您想要一个基本的解决方案,请确保排除具有相同类的 jar 文件。

对我来说,我有: javax.xml.soap.SOAPPart 位于三个不同的 jar 中: axis-saaj-1.4.jarsaaj-api-1.3.jar< /code> 和 rt.jar

There's another solution that also works.

  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.

This works because you have multiple classes in different jar files. Removing and re-adding the JRE lib will make the right classes be first.
If you want a fundamental solution make sure you exclude the jar files with the same classes.

For me I have: javax.xml.soap.SOAPPart in three different jars: axis-saaj-1.4.jar, saaj-api-1.3.jar and the rt.jar

还如梦归 2024-07-26 08:18:04

http://www.digizol.com/2008/09 /eclipse-access-restriction-on-library.html 最适合我。

在 Windows 上: Windows -> 首选项-> Java-> 编译器-> 错误/警告
-> 已弃用和受限的 API -> 禁止引用(访问规则):-> 更改为警告

在 Mac OS X/Linux 上: Eclipse -> 首选项-> Java-> 编译器-> 错误/警告
-> 已弃用和受限的 API -> 禁止引用(访问规则):-> 改为警告

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

允世 2024-07-26 08:18:04

我遇到了同样的问题。 我在网站上找到了答案:http://www.17ext.com
首先,删除 JRE 系统库。 然后,再次导入JRE系统库。

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

蓝海 2024-07-26 08:18:04

我的猜测是,您正在尝试将 Java 5 附带的标准类替换为您拥有的库中的标准类。

根据许可协议的条款,这是不允许的,但是据我所知,直到 Java 5 才强制执行。

我之前在 QName 中看到过这种情况,我通过从我拥有的 jar 中删除该类来“修复”它。

编辑
http://www.manpagez.com/man/1/java/ 注释选项“-Xbootclasspath:”

“不应部署使用此选项来覆盖 rt.jar 中的类的应用程序,因为这样做会违反 Java 2 运行时环境二进制代码许可证。”

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

“Java 技术限制。您不得修改 Java
平台接口(“JPI”,标识为包含的类
在“java”包或“java”的任何子包中
包),通过在 JPI 中创建附加类或
否则会导致增加或修改
JPI 中的类。 如果您创建一个
(i) 扩展的附加类和相关 API
Java 平台的功能,并且 (ii) 公开
出于以下目的向第三方软件开发商提供
开发调用此类的附加软件
附加 API,您必须立即广泛发布
此类API的准确规范供所有人免费使用
开发商。 您不得创建或授权您的
被许可人可以创建附加类、接口或
以任何方式标识为“java”的子包,
“javax”、“sun”或 Sun 中指定的类似约定
任何命名约定指定。”

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

郁金香雨 2024-07-26 08:18:04

我也遇到了这个错误,但是我的项目是使用 Maven 和 tycho 编译器(它是一组 OSGi插件)。 经过大量筛选有同样问题的人,但在 Eclipse 中而不是在命令行中修复它,我发现 第谷开发者论坛上的一条消息回答了我的问题,使用 pom.xml 中的配置来忽略有关访问限制的编译器警告:

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

更多信息可以在 第谷常见问题解答。 这花了我很长时间才解决,所以我想我会通过发布这个答案来帮助其他任何试图从命令行修复这些访问限制错误的人。

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.

明月夜 2024-07-26 08:18:04
  • 转到项目属性中的构建路径设置。
    <代码>Windows - > 首选项-> Java 编译器
  • 删除 JRE 系统库
  • 添加另一个“完美匹配”的 JRE,
  • 然后再次构建您的项目。 这对我有用。
  • 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.
滴情不沾 2024-07-26 08:18:04

我刚刚也遇到了这个问题。 显然我在构建路径中将 JRE 设置为 1.5 而不是 1.6。

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

披肩女神 2024-07-26 08:18:04

除了 Nels Beckman 的解决方案之外,我还有以下提示:

配置构建路径下,我必须在订单和导出下重新排列我的条目顺序。

此外,作为一名 Eclipse PDE 开发人员,我需要重新排列 MANIFEST.MF 中依赖项的顺序,将有问题的包添加到列表中的第一个。

玩这些转盘,同时运行Project > 在这期间,我能够解决这些警告。

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.

笑饮青盏花 2024-07-26 08:18:04

对我来说,我解决这个问题的方法是:

  • 转到

库下

  • 当前项目的构建路径 ,选择“JRE System Library [jdk1.8xxx]”
  • 单击编辑
  • 并选择“工作区默认 JRE(jdk1.8xx)”备用 JRE
  • 单击“完成”
  • 单击“确定”

在此处输入图像描述

注意:确保在 Eclipse/首选项(而不是项目)/ Java /安装的JRE,jdk指向JDK文件夹而不是JRE C:\ Program Files \ Java \ jdk1.8.0_74

在此处输入图像描述

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

dawn曙光 2024-07-26 08:18:04

抱歉更新旧帖子。 我收到了报告的问题,并按如下所述解决了它。

假设您使用的是 Eclipse + m2e maven 插件,如果您收到此访问限制错误,请右键单击出现错误的项目/模块 --> 属性--> 构建路径 --> 图书馆 --> 将 JDK/JRE 替换为 Eclipse 工作区中使用的 JDK/JRE。

我按照上述步骤操作,问题已解决。

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.

古镇旧梦 2024-07-26 08:18:04

如果您确定应该能够访问给定的类,那么这可能意味着您向项目中添加了多个包含具有相同名称(或路径)但内容不同的类的 jar,并且它们相互遮盖(通常是旧的自定义构建 jar 包含内置旧版本的第 3 方库)。

例如,当您添加一个实现:

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

但旧版本仅实现:

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

在代码编辑器中一切正常,但如果“旧”库掩盖了新库,则在编译期间会失败 - d2 甚至突然变得“丢失或无法访问”当它在那里时。

解决方案是检查编译时库的顺序,并确保具有正确实现的库位于第一位。

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.

风追烟花雨 2024-07-26 08:18:04

转到项目属性中的 Java 构建路径。 删除现有的 JRE 系统库
然后再次添加即Add Library-->JRE Lib--选择jre--->Finish。
最后选择订单和导出选项卡,选择 JRE Lib 并移至顶部。 就是这样。

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.

羁拥 2024-07-26 08:18:04

只需更改项目的构建路径库的顺序即可。 右键单击项目>构建路径> 配置构建路径>选择顺序和导出(选项卡)>更改条目的顺序。 我希望将“JRE系统库”移动到底部会起作用。 它对我来说非常有效。 简单又容易......!!!

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

苍风燃霜 2024-07-26 08:18:04

就我而言,构建路径 JRE 与执行环境中安装的 JRE 之间不匹配。 我进入项目> 属性> Java 编译器。 底部有一条警告消息。

我单击了“已安装的 JRE”、“执行环境”、“Java 构建路径”链接,并将 JDK 版本更改为 1.7,警告消失了。

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.

烟沫凡尘 2024-07-26 08:18:04

通过构建路径添加正确的 JRE 系统是解决方案,但您的 Eclipse 仍然可能有错误。
要解决这个问题,请转到 Java 构建路径 --> 订购和导出并将您的 JRE 系统库移动到顶部。 这解决了我的问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文