@FXML注释和FXMLLoader类未解析为Java 11和JavaFX 11中的类型 [英] @FXML annotation and FXMLLoader class not resolved to a type in Java 11 and JavaFX 11
问题描述
之前我的项目曾经是Java 8,但现在我正在使用Java 11和JavaFX 11,现在JavaFX已经从Java 11开始与Java解耦了。我没有下载JavaFX SDK,但在pom中添加了以下依赖项。 xml用于获取在早期版本中曾经是Java本身一部分的必需模块和jar文件。
Earlier my project used to be on Java 8 but now I am using Java 11 along with JavaFX 11 and now JavaFX has been decoupled from Java since Java 11. I haven't download the JavaFX SDK but added below dependency in pom.xml for getting required modules and jar files which were used to be part of Java itself in earlier versions.
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11</version>
</dependency>
但我收到编译错误无法解析为类型
on @FXML
annotation和 FXMLLoader
class。
But I am getting compilation error can not be resolved to a type
on @FXML
annotation and FXMLLoader
class.
我是否需要添加一些其他/额外的依赖项来解决此问题?
Do I need to add some other/extra dependencies to resolve this issue?
推荐答案
FXML( @FXML
注释,FXMLLoader ...)被移植到带有Java 9版本的模块 javafx.fxml
。
FXML (@FXML
annotation, FXMLLoader...) were moved to the module javafx.fxml
with the Java 9 release.
在JavaFX 11之前,无论何时调用与JavaFX相关的内容,您都可以在SDK中使用所有javafx模块。
Before JavaFX 11, whenever you were calling something JavaFX related, you had all the javafx modules available within the SDK.
但是现在你必须包括你需要的那些:
But now you have to include the ones you need:
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>11</version>
</dependency>
请注意 javafx.controls
取决于 javafx.graphics
和 java.base
,因此您不需要包含这些内容。并且 javafx.fxml
直接取决于 javafx.base
。
Note that javafx.controls
depends on javafx.graphics
and java.base
, so you don't need to include those. And javafx.fxml
directly depends on javafx.base
.
这篇关于@FXML注释和FXMLLoader类未解析为Java 11和JavaFX 11中的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!