我在Intellij下使用Maven编程我的第一个JavaFX v17.0项目。一切都很好,我能够创建一个JavaFX视图控制器并显示它。但是,当我将这些行添加到module-info:
时,问题出现了。requires Rserve;
requires REngine;
对应于pom.xml中的依赖项:
<!-- https://mvnrepository.com/artifact/org.rosuda.REngine/Rserve -->
<dependency>
<groupId>org.rosuda.REngine</groupId>
<artifactId>Rserve</artifactId>
<version>1.8.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.rosuda.REngine/REngine -->
<dependency>
<groupId>org.rosuda.REngine</groupId>
<artifactId>REngine</artifactId>
<version>2.1.0</version>
</dependency>
当我编译时,我得到这些错误:
...
Checking sources
Copying resources... [first-javafx-try]
Parsing java... [first-javafx-try]
java: the unnamed module reads package java.io from both api.classic and java.base
java: the unnamed module reads package java.lang from both api.classic and java.base
java: module api.classic reads package java.lang from both java.base and api.classic
java: module api.classic reads package java.io from both java.base and api.classic
java: module REngine reads package java.lang from both java.base and api.classic
java: module REngine reads package java.io from both java.base and api.classic
java: module Rserve reads package java.lang from both java.base and api.classic
java: module Rserve reads package java.io from both java.base and api.classic
Checking dependencies... [first-javafx-try]
...
我尝试将这些行添加到vm配置中:
--add-exports java.base/java.lang=ALL-UNNAMED --add-exports java.base/java.io=ALL-UNNAMED
但它仍然不工作。
你能解释一下错误的来源和解决方法吗?
更新事实上,RServe和REngine的依赖关系不是模块化的,但我不知道如何处理。
有关更多信息,请参阅完整的pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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>com.example</groupId>
<artifactId>demo</artifactId>
<version>1.0-SNAPSHOT</version>
<name>demo</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>5.7.1</junit.version>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.rosuda.REngine/Rserve -->
<dependency>
<groupId>org.rosuda.REngine</groupId>
<artifactId>Rserve</artifactId>
<version>1.8.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.rosuda.REngine/REngine -->
<dependency>
<groupId>org.rosuda.REngine</groupId>
<artifactId>REngine</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>17-ea+11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>17-ea+11</version>
</dependency>
<dependency>
<groupId>org.controlsfx</groupId>
<artifactId>controlsfx</artifactId>
<version>11.1.0</version>
</dependency>
<dependency>
<groupId>com.dlsc.formsfx</groupId>
<artifactId>formsfx-core</artifactId>
<version>11.3.2</version>
<exclusions>
<exclusion>
<groupId>org.openjfx</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.kordamp.bootstrapfx</groupId>
<artifactId>bootstrapfx-core</artifactId>
<version>0.4.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.6</version>
<executions>
<execution>
<!-- Default configuration for running with: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>com.example.demo/root.circlepong.CirclePongApp</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
和module-info:
module root {
requires javafx.controls;
requires javafx.fxml;
requires Rserve;
requires REngine;
opens root.circlepong to javafx.fxml;
exports root.circlepong;
opens root.switchscene to javafx.fxml;
exports root.switchscene;
opens root.mvvmfxFirsttry to javafx.fxml;
exports root.mvvmfxFirsttry;
}
更新2
当运行编译命令时,我发现Intellij运行命令:
C:UsersThibault.jdksopenjdk-17.0.1binjava.exe "-javaagent:D:IntelliJ IDEA 2021.2.2libidea_rt.jar=52247:D:IntelliJ IDEA 2021.2.2bin" -Dfile.encoding=UTF-8 -classpath "D:ProgrammationMASI1.5CarteAPuceJavaCardsToolslibapi_classic-3.1.0.jar;D:JavaProgMASI_Projet_IntegremavenJava11Projecttargetclasses;C:Program FilesJavaFXjavafx-sdk-17.0.6libjavafx-swt.jar;C:Program FilesJavaFXjavafx-sdk-17.0.6libjavafx.web.jar;C:Program FilesJavaFXjavafx-sdk-17.0.6libjavafx.base.jar;C:Program FilesJavaFXjavafx-sdk-17.0.6libjavafx.fxml.jar;C:Program FilesJavaFXjavafx-sdk-17.0.6libjavafx.media.jar;C:Program FilesJavaFXjavafx-sdk-17.0.6libjavafx.swing.jar;C:Program FilesJavaFXjavafx-sdk-17.0.6libjavafx.controls.jar;C:Program FilesJavaFXjavafx-sdk-17.0.6libjavafx.graphics.jar;C:UsersThibault.m2repositoryorgrosudaREngineRserve1.8.1Rserve-1.8.1.jar;C:UsersThibault.m2repositoryorgrosudaREngineREngine2.1.0REngine-2.1.0.jar" root.switchscene.SwitchSceneApp --module-path C:Program FilesJavaFXjavafx-sdk-17.0.6lib --add-modules javafx.controls,javafx.fxml
在这里,我们可以看到在类路径中有一个jar' api_classic-3.1.0.jar',但是我从来没有指定它,我如何从自动命令中删除它?
我发现问题来自于'D: programming MASI1.5 carpusuce JavaCardsToolslibapi_classic-3.1.0.jar'添加的jar。由于我无法从Intellij自动命令中删除这一行,所以我删除了jar,现在一切正常。这可能不是最好的方法,但它是有效的。