出于某种原因,JavaFX 和 RabbitMQ 不想在项目中一起工作!当我添加 JavaFX 库时,类无法导入 RabbitMQ 方法,即使库也已连接。当我删除 JavaFX 库时,RabbitMQ 工作得很好。这些是根本不兼容还是我错过了一些关键设置?
您可以在下面看到我的 module-info.java 文件:
module org.example.demo {
requires javafx.controls;
requires javafx.fxml;
opens org.example.demo to javafx.fxml;
exports org.example.demo;
}
还有我的 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>org.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.10.0</junit.version>
</properties>
<dependencies>
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
<version>5.20.0</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>19.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>19.0.2</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.11.0</version>
<configuration>
<source>19</source>
<target>19</target>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<executions>
<execution>
<!-- Default configuration for running with: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>org.example.demo/org.example.demo.MessengerApplication</mainClass>
<launcher>app</launcher>
<jlinkZipName>app</jlinkZipName>
<jlinkImageName>app</jlinkImageName>
<noManPages>true</noManPages>
<stripDebug>true</stripDebug>
<noHeaderFiles>true</noHeaderFiles>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Rabbit
amqp-client
是一个 自动模块,自动模块名称在 META-INF/MANIFEST.MF
文件中的 amqp-client-5.20.0.jar
中定义。
它的价值:
Automatic-Module-Name: com.rabbitmq.client
要将 amqp-client 作为模块使用,您需要在您的
module-info.java
中引入此模块:
requires com.rabbitmq.client;
所以,你的
module-info.java
将变成:
module org.example.demo {
requires javafx.controls;
requires javafx.fxml;
requires com.rabbitmq.client;
opens org.example.demo to javafx.fxml;
exports org.example.demo;
}