我有一个关于Mavenbuilds的问题。我想在Eclipse IDE中的一个Mavenbuilds中创建一个小的javafx测试程序,我使用的是JavaSE 18和JavaFX 19。所以现在如果我想运行-〉Maven build...并设置目标“clean javafx:run”,我会收到以下失败/错误消息:
[[1;34mINFO[m] Scanning for projects...
[[1;34mINFO[m]
[[1;34mINFO[m] [1m---------------------< [0;36morg.openjfx:HauserProgram[0;1m >----------------------[m
[[1;34mINFO[m] [1mBuilding HauserProgram 0.0.1-SNAPSHOT[m
[[1;34mINFO[m] [1m--------------------------------[ jar ]---------------------------------[m
[[1;34mINFO[m]
[[1;34mINFO[m] [1m--- [0;32mmaven-clean-plugin:2.5:clean[m [1m(default-clean)[m @ [36mHauserProgram[0;1m ---[m
[[1;34mINFO[m] Deleting D:\eclipse-workspace\javafxmav\target
[[1;34mINFO[m]
[[1;34mINFO[m] [1m>>> [0;32mjavafx-maven-plugin:0.0.8:run[m [1m(default-cli)[0;1m > [0;1mprocess-classes[m @ [36mHauserProgram[0;1m >>>[m
[[1;34mINFO[m]
[[1;34mINFO[m] [1m--- [0;32mmaven-resources-plugin:2.6:resources[m [1m(default-resources)[m @ [36mHauserProgram[0;1m ---[m
[[1;34mINFO[m] Using 'UTF-8' encoding to copy filtered resources.
[[1;34mINFO[m] Copying 3 resources
[[1;34mINFO[m]
[[1;34mINFO[m] [1m--- [0;32mmaven-compiler-plugin:3.1:compile[m [1m(default-compile)[m @ [36mHauserProgram[0;1m ---[m
[[1;34mINFO[m] Changes detected - recompiling the module!
[[1;34mINFO[m] Compiling 6 source files to D:\eclipse-workspace\javafxmav\target\classes
[[1;34mINFO[m] -------------------------------------------------------------
[[1;31mERROR[m] COMPILATION ERROR :
[[1;34mINFO[m] -------------------------------------------------------------
[[1;31mERROR[m] /D:/eclipse-workspace/javafxmav/src/main/java/module-info.java:[6,24] module not found: javafx.base
[[1;31mERROR[m] /D:/eclipse-workspace/javafxmav/src/main/java/module-info.java:[7,24] module not found: javafx.controls
[[1;31mERROR[m] /D:/eclipse-workspace/javafxmav/src/main/java/module-info.java:[8,35] module not found: javafx.fxml
[[1;31mERROR[m] /D:/eclipse-workspace/javafxmav/src/main/java/module-info.java:[9,35] module not found: javafx.graphics
[[1;31mERROR[m] /D:/eclipse-workspace/javafxmav/src/main/java/module-info.java:[11,32] module not found: org.apache.poi.poi
[[1;34mINFO[m] 5 errors
[[1;34mINFO[m] -------------------------------------------------------------
[[1;34mINFO[m] [1m------------------------------------------------------------------------[m
[[1;34mINFO[m] [1;31mBUILD FAILURE[m
[[1;34mINFO[m] [1m------------------------------------------------------------------------[m
[[1;34mINFO[m] Total time: 0.683 s
[[1;34mINFO[m] Finished at: 2022-11-01T12:45:40+01:00
[[1;34mINFO[m] [1m------------------------------------------------------------------------[m
[[1;31mERROR[m] Failed to execute goal [32morg.apache.maven.plugins:maven-compiler-plugin:3.1:compile[m [1m(default-compile)[m on project [36mHauserProgram[m: [1;31mCompilation failure[m: Compilation failure:
[[1;31mERROR[m] /D:/eclipse-workspace/javafxmav/src/main/java/module-info.java:[6,24] module not found: javafx.base
[[1;31mERROR[m] /D:/eclipse-workspace/javafxmav/src/main/java/module-info.java:[7,24] module not found: javafx.controls
[[1;31mERROR[m] /D:/eclipse-workspace/javafxmav/src/main/java/module-info.java:[8,35] module not found: javafx.fxml
[[1;31mERROR[m] /D:/eclipse-workspace/javafxmav/src/main/java/module-info.java:[9,35] module not found: javafx.graphics
[[1;31mERROR[m] /D:/eclipse-workspace/javafxmav/src/main/java/module-info.java:[11,32] module not found: org.apache.poi.poi
[[1;31mERROR[m] -> [1m[Help 1][m
[[1;31mERROR[m]
[[1;31mERROR[m] To see the full stack trace of the errors, re-run Maven with the [1m-e[m switch.
[[1;31mERROR[m] Re-run Maven using the [1m-X[m switch to enable full debug logging.
[[1;31mERROR[m]
[[1;31mERROR[m] For more information about the errors and possible solutions, please read the following articles:
[[1;31mERROR[m] [1m[Help 1][m http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
这里是我的module-info.java:
module HauserProgram {
exports de.hauserwein;
requires java.sql;
requires javafx.base;
requires javafx.controls;
requires transitive javafx.fxml;
requires transitive javafx.graphics;
requires java.desktop;
requires org.apache.poi.poi;
opens de.hauserwein to javafx.fxml, javafx.base, javafx.controls, javafx.graphics;
}
和我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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.openjfx</groupId>
<artifactId>HauserProgram</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>18</maven.compiler.source>
<maven.compiler.target>18</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.30</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>18</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.2.3</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
<version>2.19.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<configuration>
<mainClass>de.hauserwein/Main.java</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
我尝试将javafx sdk添加到buildpath中,在pom.xml中测试了一些不同的javafx版本18/19,并希望将org.openjfx添加到module-info.java文件中...
如果我用“作为JavaApplication运行”启动它,它会工作,只有导出到一个可运行的文件不会工作。
1条答案
按热度按时间f4t66c6m1#
首先,确保pom中包含所有依赖项:
然后,听起来您对eclipse中的构建路径有依赖,而不是对maven项目有依赖。运行
mvn clean install
来解决依赖问题。(And请不要对工件使用
<groupId>org.openjfx</groupId>
,这会导致不必要的混淆。)