Eclipse 对 jfxrt.jar 类的访问限制发出警告

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24743027/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 22:07:02  来源:igfitidea点击:

Eclipse gives warning on access restriction for jfxrt.jar classes

eclipsemavenjavafxjava-8eclipse-kepler

提问by Japheth Ongeri - inkalimeva

I'm using eclipse kepler with java SE 1.8 jdk system library but when I use any javafx classes or methods eclipse gives a warning like Access restriction: The type 'TableColumn<?,?>' is not API (restriction on required library 'C:\Program Files\Java\jdk1.8.0_05\jre\lib\ext\jfxrt.jar').

我将 eclipse kepler 与 java SE 1.8 jdk 系统库一起使用,但是当我使用任何 javafx 类或方法时,eclipse 会发出类似Access restriction: The type 'TableColumn<?,?>' is not API (restriction on required library 'C:\Program Files\Java\jdk1.8.0_05\jre\lib\ext\jfxrt.jar').

I have tried adding an access rule to the system library to allow access for all jars in the library using the wildcard *but the warning is still there. Am also using maven for building project. The code works but the warning is nagging and is affecting readability as I code. Any help is appreciated.

我尝试向系统库添加访问规则,以允许使用通配符访问库中的所有 jar,*但警告仍然存在。我也在使用 maven 来构建项目。代码有效,但警告是唠叨,并且在我编码时影响可读性。任何帮助表示赞赏。

Edit: I also tried adding @SuppressWarnings("restriction")at the beginning of my classes but this still doesn't solve the unknown cause and hides all other restriction warnings that I may need to see

编辑:我也尝试@SuppressWarnings("restriction")在课程开始时添加,但这仍然无法解决未知原因并隐藏了我可能需要查看的所有其他限制警告

采纳答案by ltalhouarne

You can choose ignorein the following settings:

您可以ignore在以下设置中进行选择:

Windows -> Preferences -> Java -> Compiler -> Errors/Warnings
(Project) Properties -> Java Compiler -> Errors/Warnings

Use filter to find "Forbidden reference"

使用过滤器查找 "Forbidden reference"

Forbidden reference (access rules): Change it to "ignore"

Forbidden reference (access rules): 改成“ ignore

enter image description here

在此处输入图片说明

回答by Hollis Waite

I'm able to get past this by reconfiguring Java library. For example, explicitly selecting Oracle JDK does the trick.

我可以通过重新配置 Java 库来解决这个问题。例如,明确选择 Oracle JDK 就可以解决问题。

Configure Build Path

配置构建路径

Edit Java lib

编辑 Java 库

Select explicit JDK

选择显式 JDK

回答by Thach Van

The easy way is to install e(fx)clipse - a plugin for Eclipse to support JavaFX:

简单的方法是安装 e(fx)clipse - Eclipse 支持 JavaFX 的插件:

  1. Select Help -> Install New Software
  2. Click Add button to add the following site:
  3. Click OK
  4. In the "Work with" dropdown list, select the recently added site "efxclipse"
  5. Check the checkbox "e(fx)clipse - install" to install all components of this selection
  6. Move to next steps to finish the installation
  7. Restart your Eclipse. If it still doesn't recognize JavaFX library, restart it again.
  1. 选择帮助 -> 安装新软件
  2. 单击添加按钮添加以下站点:
  3. 单击确定
  4. 在“Work with”下拉列表中,选择最近添加的站点“efxclipse”
  5. 选中复选框“e(fx)clipse - install”以安装此选择的所有组件
  6. 转到下一步以完成安装
  7. 重新启动 Eclipse。如果它仍然无法识别 JavaFX 库,请再次重新启动它。

Original information can be found here: https://www.eclipse.org/efxclipse/install.html#for-the-lazy

原始信息可以在这里找到:https: //www.eclipse.org/efxclipse/install.html#for-the-lazy

回答by Has QUIT--Anony-Mousse

Add an access ruleto allow access to javafx/**.

添加访问规则以允许访问javafx/**.

See also this answer: https://stackoverflow.com/a/32062263/1060350

另请参阅此答案:https: //stackoverflow.com/a/32062263/1060350

For all I can tell, this is a bug in Eclipse in my opinion. I also could not find a way to configure this globally in Eclipse, but you need to redo it for every project.

就我所知,在我看来,这是 Eclipse 中的一个错误。我也找不到在 Eclipse 中全局配置它的方法,但是您需要为每个项目重做它。

Navigate to Project settings, Build path, Libraries, JRE. Click on "Access rules" which should have "No rules defined" usually. Add a new rule: "Accessible", and enter the pattern "javafx/**".

导航到项目设置、构建路径、库、JRE。单击通常应该具有“未定义规则”的“访问规则”。添加新规则:“可访问”,并输入模式“ javafx/**”。

This tells the Eclipse Java compiler that javafx.*is an official API that you are allowed to use, so the warning goes away.

这会告诉 Eclipse Java 编译器这javafx.*是您可以使用的官方 API,因此警告消失。

Clearly, allowingaccess to javafx only is much better than ignoring the warning.

显然,只允许访问 javafx 比忽略警告要好得多。

The reason why *did not work is because you did not read the wildcard definition. In the access rules, *only matches once, you need **to match at any depth. I.e. *will allow access to javafx.SomeClassbut not not javafx.scene.SomeClass...

*没有工作的原因是因为你没有阅读通配符定义。在访问规则中,*只匹配一次,需要**任意深度匹配。即*允许访问javafx.SomeClass,但不不javafx.scene.SomeClass...

回答by broc.seib

Add an access rule for javafx.

添加访问规则javafx

Right click your project > Properties > Java Build Path > Libraries tab, then:

右键单击您的项目 > 属性 > Java 构建路径 > 库选项卡,然后:

  • Expand JRE System Library
  • select Access Rules, click Edit...button
  • click Add...
  • choose Resolution: Accessible
  • set Rule Pattern: javafx/**
  • click OK
  • click OK
  • 展开 JRE 系统库
  • 选择访问规则,点击Edit...按钮
  • 点击 Add...
  • 选择分辨率: Accessible
  • 设置规则模式: javafx/**
  • 点击 OK
  • 点击 OK

add access to lib for jfxrt

为 jfxrt 添加对 lib 的访问