为什么Maven看不到JavaFX图形模块(而Eclipse看不到)
我有一个多模块Maven项目,其中一个模块使用JavaFX。虽然在Eclipse中一切都编译得很好,但是 mvn干净编译为什么Maven看不到JavaFX图形模块(而Eclipse看不到),java,maven,javafx,java-module,Java,Maven,Javafx,Java Module,我有一个多模块Maven项目,其中一个模块使用JavaFX。虽然在Eclipse中一切都编译得很好,但是 mvn干净编译 [INFO] ------------------------------------------------------------- [ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR] /C:/Users/egr/e
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/egr/eclipse-workspace/demo/mod1/src/main/java/nl/eddy/mod1/Launch.java:[4,26] package javafx.scene.robot does not exist
[ERROR] /C:/Users/egr/eclipse-workspace/demo/mod1/src/main/java/nl/eddy/mod1/Launch.java:[15,21] cannot find symbol
symbol: class Robot
location: class nl.eddy.mod1.Launch
[INFO] 2 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for demo 0.0.1-SNAPSHOT:
[INFO]
[INFO] demo ............................................... SUCCESS [ 0.368 s]
[INFO] mod1 ............................................... FAILURE [ 2.541 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.161 s
[INFO] Finished at: 2020-02-11T13:08:56+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project mod1: Compilation failure: Compilation failure:
[ERROR] /C:/Users/egr/eclipse-workspace/demo/mod1/src/main/java/nl/eddy/mod1/Launch.java:[4,26] package javafx.scene.robot does not exist
[ERROR] /C:/Users/egr/eclipse-workspace/demo/mod1/src/main/java/nl/eddy/mod1/Launch.java:[15,21] cannot find symbol
[ERROR] symbol: class Robot
[ERROR] location: class nl.eddy.mod1.Launch
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
返回此错误
package javafx.scene.robot does not exist
maven似乎看不到包含javafx.scene.robot
的javafx.graphics
模块(但Eclipse确实看到了它,因为它没有给出编译错误)。如何让Maven编译这段代码
我已经创建了我的应用程序的一个小版本来复制这个。以下是文件:
Main pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>nl.eddy</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release> <!-- JDK Version -->
</configuration>
</plugin>
</plugins>
</build>
<modules>
<module>mod1</module>
</modules>
</project>
module-info.java
module nl.eddy.mod1 {
requires javafx.controls;
// requires javafx.graphics; uncommenting this does not change maven's message
}
mvn干净编译的输出
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/egr/eclipse-workspace/demo/mod1/src/main/java/nl/eddy/mod1/Launch.java:[4,26] package javafx.scene.robot does not exist
[ERROR] /C:/Users/egr/eclipse-workspace/demo/mod1/src/main/java/nl/eddy/mod1/Launch.java:[15,21] cannot find symbol
symbol: class Robot
location: class nl.eddy.mod1.Launch
[INFO] 2 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for demo 0.0.1-SNAPSHOT:
[INFO]
[INFO] demo ............................................... SUCCESS [ 0.368 s]
[INFO] mod1 ............................................... FAILURE [ 2.541 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.161 s
[INFO] Finished at: 2020-02-11T13:08:56+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project mod1: Compilation failure: Compilation failure:
[ERROR] /C:/Users/egr/eclipse-workspace/demo/mod1/src/main/java/nl/eddy/mod1/Launch.java:[4,26] package javafx.scene.robot does not exist
[ERROR] /C:/Users/egr/eclipse-workspace/demo/mod1/src/main/java/nl/eddy/mod1/Launch.java:[15,21] cannot find symbol
[ERROR] symbol: class Robot
[ERROR] location: class nl.eddy.mod1.Launch
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
来自mvn-X compile的日志的编译器详细信息
Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-24T20:41:47+02:00)
Maven home: C:\apps\apache-maven-3.6.0\bin\..
Java version: 12.0.2, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk-12.0.2
Default locale: en_US, platform encoding: Cp1252
OS name: "windows server 2012 r2", version: "6.3", arch: "amd64", family: "windows"
当我将maven编译器插件发布元素的值改为12而不是11时,编译就进行得很顺利。即,与实际运行Maven的编译器的值相同。非常感谢@JosePereda,请参阅注释。编译时使用的JDK是什么?(运行mvn-X compile
找出答案)@JoséPereda我已经在上面的帖子中添加了mvn-X compile
输出的开头。我无法重现你的问题。确保%PATH%
中没有任何其他JDK,因为Maven会选择它。您还可以尝试添加到编译器插件配置中:/path/to/javactrue
,其中路径指向JDK 12.0.2above@JoséPereda感谢您为我指出编译器插件配置。我只是把版本改成了12,是11。
Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-24T20:41:47+02:00)
Maven home: C:\apps\apache-maven-3.6.0\bin\..
Java version: 12.0.2, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk-12.0.2
Default locale: en_US, platform encoding: Cp1252
OS name: "windows server 2012 r2", version: "6.3", arch: "amd64", family: "windows"