Eclipse gives warning on access restriction for jfxrt.jar classes

后端 未结 5 1213
陌清茗
陌清茗 2021-02-04 02:57

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 \'Tabl

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-04 03:10

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

    See also this answer: 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.

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

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

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

    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.SomeClass but not not javafx.scene.SomeClass...

提交回复
热议问题