20

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').

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.

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

Tunaki
  • 132,869
  • 46
  • 340
  • 423
  • 1
    possible duplicate of [Using JavaFX in JRE 8](http://stackoverflow.com/questions/22812488/using-javafx-in-jre-8) – Hilikus Mar 06 '15 at 01:57
  • 1
    You have the wildcard syntax wrong. You used `*` which is non recursive, you meant to use `**`, and you *should* have used `javafx/**` only. See my answer below. – Has QUIT--Anony-Mousse Jan 20 '17 at 12:48

5 Answers5

34

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

Configure Build Path

Edit Java lib

Select explicit JDK

Hollis Waite
  • 1,079
  • 1
  • 20
  • 31
8

The easy way is to install e(fx)clipse - a plugin for Eclipse to support 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.

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

Thach Van
  • 1,381
  • 16
  • 19
4

You can choose ignore in the following settings:

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

Use filter to find "Forbidden reference"

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

enter image description here

ltalhouarne
  • 4,586
  • 2
  • 22
  • 31
  • 7
    Thanks for the help, but if I could fix the cause of the warning rather than suppress it that would be better. – Japheth Ongeri - inkalimeva Jul 14 '14 at 18:21
  • 4
    I would strongly discourage that solution and it shouldn't be the accepted one. You will change the settings for ALL libraries, not only JavaFX. One should make sure to use the JDK in the build path as indicated by the answer below... – mmey Jul 08 '16 at 09:02
  • 1
    Rather than suppress the warning, just add the proper access rules. See my new answer below. – broc.seib May 21 '17 at 06:43
4

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

Community
  • 1
  • 1
Has QUIT--Anony-Mousse
  • 76,138
  • 12
  • 138
  • 194
2

Add an access rule for javafx.

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

  • Expand JRE System Library
  • select Access Rules, click Edit... button
  • click Add...
  • choose Resolution: Accessible
  • set Rule Pattern: javafx/**
  • click OK
  • click OK

add access to lib for jfxrt

broc.seib
  • 21,643
  • 8
  • 63
  • 62