Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access restriction on JavaFX classes in Eclipse Oxygen

I'm using Eclipse Oxygen 4.7.0 in Ubuntu 17.04 with Oracle JDK 8u144.

Any code that refers to JavaFX classes in packages javafx.*, e.g. javafx.application.Application is (incorrectly) reported as an error

Access restriction: The type 'ScrollPane' is not API (restriction on required library '/opt/jdk1.8.0_144/jre/lib/ext/jfxrt.jar')

This appears to be related to the "Java System Library" JavaSE-1.8. The jfxrt.jar has "Access rules" you can view in Properties -> Java Build Path, these only permit javax/, java/, org.w3c.* etc, none of which are even in the jfxrt.jar.

I can workaround this issue in two different ways

  • Changing Preferences -> Java -> Compiler -> Errors and Warnings -> Deprecated and Restricted API -> Forbidden Reference (access rules) to not be an error.
  • Manually changing the system library from "JavaSE-1.8" to "Workspace default JRE" via Properties -> Java Build Path -> JRE System Library -> Edit

Neither of these methods is ideal as I have a large number of Eclipse projects to tweak, and would prefer the forbidden reference checks are left enabled to catch genuine errors.

Note this is also an issue when importing projects via the standard Gradle Import plugin included in Eclipse.

Is there anyway to avoid this issue, perhaps via Gradle configuration, or is a known bug/feature that will be fixed?

like image 626
Adam Avatar asked Oct 17 '22 07:10

Adam


1 Answers

This is discussed at length in Eclipse Bug 431067.

In addition to the workarounds in the question, the easiest is to install the e(fx)clipse plugin - https://www.eclipse.org/efxclipse/install.html.

This does the magic of configuring the necessary access restrictions within the JDK automagically.

like image 116
Adam Avatar answered Nov 11 '22 07:11

Adam