问题描述
我当前的Eclipse是Oxygen.2版本(4.7.2),其中有Java 9.0.1.从本质上讲,Java 9可以工作,尤其是自动导入(适用于普通"类和程序包)有效,但是自动导入(和自动完成)不适用于javafx.*
.如果我手动键入import java
并按 + ,则会弹出匹配包列表,在其中可以看到javafx.*
层次结构.但是当我输入import javafx.stage
并按 + ,它将自动添加.*;
,并且在程序包中不显示任何类.当我在方法正文中的某处键入Stage
并按 + 时,没有任何建议.但是,当我键入一个导入(例如import javafx.stage.Stage
)时,代码便会编译并运行.
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 +, then list of matching packages pops up where I can see javafx.*
hierarchy. But when I type e.g. import javafx.stage
and press + it automatically adds .*;
and does not display any classes in the package. When I type Stage
somewhere in the method body and press +, there are no suggestions for it. However when I type add an import (like import javafx.stage.Stage
) then code compiles and runs.
任何线索都说明了如何解决自动完成和自动导入功能(正如我所说的那样,该功能适用于其他类,例如java.time.LocalDateTime
或其他).
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).
推荐答案
javafx*
类由于受访问规则控制对系统程序包的访问而在代码完成期间被阻止.例如,查看 Eclipse错误527353 动态计算Eclipse Oxygen中尚未完成可访问软件包的列表.结果,只有静态配置文件可以使用.该文件当前提到:
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:
由于根据 JEP 261 进行的动态计算包括javafx
软件包-如果有的话- ,我认为静态配置文件也应列出这些配置文件,或者仅出于完全依赖 JPMS 规则而被放弃.
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.
但是,可以通过在
Java Build Path > Libraries > JRE System Library > Access rules
.
这篇关于如何在Eclipse中为JavaFX类启用自动导入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!