2

My current Eclipse is Oxygen.2 Release (4.7.2) and there's Java 9.0.1. Essentially Java 9 works and particularly auto import works (for "ordinary" classes and packages), but auto import (and autocompletion) does not work for javafx.*. If I manually type import java and press Ctrl+Space, then list of matching packages pops up where I can see javafx.* hierarchy. But when I type e.g. import javafx.stage and press Ctrl+Space it automatically adds .*; and does not display any classes in the package. When I type Stage somewhere in the method body and press Ctrl+Space, there are no suggestions for it. However when I type add an import (like import javafx.stage.Stage) then code compiles and runs.

Any clues how to fix auto completion and auto import feature (which, as I said, works for other classes, like for instance java.time.LocalDateTime or many othres).

SedJ601
  • 12,173
  • 3
  • 41
  • 59
Cromax
  • 1,822
  • 1
  • 23
  • 35
  • 1
    It works fine for me. A couple of things that *might* be happening: 1. are you configuring your project as a modular project (i.e. do you have a `module-info.java` file in the project)? If so, you need to make sure you include the appropriate JavaFX modules in there (typically `requires javafx.controls;`). 2. Which JDK are you using? JavaFX is included with Oracle JDK, but not with OpenJDK. – James_D Feb 25 '18 at 02:35
  • Ad.1) No, it is not modular project, Ad.2) It's Oracle's. I even see explicit modules of javafx in the Java Build Path/Libraries/Modulepath/JRE System Library [JavaSE-9], eg. javafx.graphics, javafx.base, javafx.swing and so on. And as I said, the code runs (from within the Eclipse) with JavaFX stuff, just imports are not being completed (and the packages are being seen, just not the classes). It's just so strange... – Cromax Feb 25 '18 at 02:50
  • I've just noticed, that when Eclipse offers a quick fix for class that has no import (e.g. `ObservableList`) then it offers import action and it actually does add the import statement! It just doesn't work "the usual way", I mean via Ctrl+Space. Damn, that hurts! ;-) – Cromax Feb 25 '18 at 02:53
  • Yeah, that's weird. Like I said, with the same setup it works "normally" for me. If you open the project properties, Java Build Path, Libraries, and expand Modulepath and JRE System Library, do you see the JavaFX modules? – James_D Feb 25 '18 at 03:12
  • Yes, I can see them, just as I said: *I even see explicit modules of javafx in the Java Build Path/Libraries/Modulepath/JRE System Library [JavaSE-9], eg. **javafx.graphics**, **javafx.base**, **javafx.swing** and so on*. If they were not there, I could possibly blame it... But they are there... And the code runs (well, but these are separate settings...). Just no clue what might be amiss. – Cromax Feb 25 '18 at 03:19

1 Answers1

8

javafx* classes are blocked during code completion due to access rules governing the access to system packages. Looking at, e.g., Eclipse bug 527353 the mechanism for dynamically computing the list of accessible packages had not been finalized in Eclipse Oxygen. As a result, only a static profile can be used. That file currently mentions:

NOTE: The JavaSE-9 profile is not yet finalized.

Since dynamic computation according to JEP 261 includes the javafx packages - if available -, I think the static profile should list those as well, or be abandoned in favor of fully relying on JPMS rules, only.

You can, however, avoid the problem by explicitly defining an access rule granting access to javafx/** at

Java Build Path > Libraries > JRE System Library > Access rules.

Stephan Herrmann
  • 7,963
  • 2
  • 27
  • 38
  • The funny thing is, that javafx *packages* themselves are on the list, when you type `import java|` and then press Ctrl-Space, where | indicates cursor position. You can see packages (not classes in them). Access rules were stuff I was using in Java 8. (BTW: There is a difference how you state your JRE to be used in Eclipse. Profile does not see javafx classes for the reasons you've described, but pointing directly to a given JRE worked out of box, AFAIR). – Cromax Feb 28 '18 at 12:12