[英]build.fxbuild returns error: "module not found: javafx.controls", "error: module not found: javafx.fxml" when trying to Generate ant build and run
[英]Maven module not found: javafx.fxml
我正在嘗試制作一個多模塊 maven 項目。 第一個模塊是 JavaFX,第二個模塊是 SpringBoot,但我對 JavaFX 有疑問。
當我運行mvn clean install
我得到這些錯誤: module not found: javafx.fxml
, module not found: javafx.controls
,找不到module not found: javafx.graphics
模塊信息.java:
module example {
requires javafx.fxml;
requires javafx.controls;
requires javafx.graphics;
}
我的 pom.xml 中確實有 javafx,如下所示:
<properties>
<maven.compiler.source>15</maven.compiler.source>
<maven.compiler.target>15</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>11.0.1</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>16-ea+5</version>
</dependency>
</dependencies>
我的應用程序運行沒有問題,但 maven 似乎與 javafx 有某種問題。
我使用 IntelliJ IDEA。
供日后參考。
好像我自己找到了答案。
問題是我忘了添加這個
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>15</source>
<target>15</target>
</configuration>
</plugin>
</plugins>
</build>
到我的pom.xml
為javafx-controls
添加第三個依賴項或將javafx-graphics
替換為javafx-controls
我在IntelliJ IDEA中工作,也遇到了這個問題。 沒有任何效果,我在 inte.net 上沒有找到一個單一的解決方案,但后來我查看了文件 > 項目結構 > 問題,我看到了以下行(在我的例子中還有其他 3 行)
Library Maven: org.openjfx:javafx-controls:linux:16 is not used [Fix]
所以我按下 [Fix],其中一個選項是“Add to Dependencies”,選擇后會出現以下消息:
Library `Maven: org.openjfx:javafx-controls:linux:16` will be added to the selected modules:
和一個由一個以我的項目名稱命名的模塊組成的列表。
我點擊“確定”,然后點擊“確定”,總而言之,發生了一個重大變化。
原來我錯過了以下行:
<orderEntry type="library" name="Maven: org.openjfx:javafx-controls:linux:16" level="project" />
以及另外 3 個與文件 ProjectName.iml 中的javafx-fxml
、 javafx-base
和javafx-graphics
非常相似的文件,其中 ProjectName 是我的項目的名稱。
我不是專家,所以我不知道我剛剛做了什么,但希望這能幫助那些發現自己處於同樣情況的可憐人。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.