我正在创建简单的聊天应用程序,但在 module-info.java 中遇到问题。在我的 Maven pom.xml 中有以下内容。并且两个模块与网络套接字模块发生冲突。我如何限制并仅使用 Tyrus 客户端 jar 而不是 web-socket 模块。这样我就可以避免冲突。我花了半天时间,但没有通过互联网获得解决方案。Tyrus-core 也采用 tomcat-websocket。如何限制不走jakarta websocket请帮忙解决
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>JavaChatApplication</groupId>
<artifactId>JavaChatApplication</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<!--
https://mvnrepository.com/artifact/org.kordamp.bootstrapfx/bootstrapfx-core -->
<dependency>
<groupId>org.kordamp.bootstrapfx</groupId>
<artifactId>bootstrapfx-core</artifactId>
<version>0.4.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.controlsfx/controlsfx -->
<dependency>
<groupId>org.controlsfx</groupId>
<artifactId>controlsfx</artifactId>
<version>11.1.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
<version>3.1.6</version>
</dependency>
<dependency>
<groupId>org.glassfish.tyrus</groupId>
<artifactId>tyrus-client</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.9</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.9</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>17</release>
</configuration>
</plugin>
</plugins>
</build>
</project>
moudle-info.xml
module com.example.javachatapplication {
requires javafx.controls;
requires javafx.fxml;
requires org.controlsfx.controls;
requires org.kordamp.bootstrapfx.core;
requires jakarta.websocket;
requires org.slf4j;
opens com.client.javachatapplication to javafx.fxml;
exports com.client.javachatapplication;
}
项目结构
├── build.fxbuild
├── pom.xml
├── src
│ ├── application
│ │ ├── application.css
│ │ └── Main.java
│ ├── main
│ │ ├── java
│ │ │ ├── com
│ │ │ │ ├── client
│ │ │ │ │ └── javachatapplication
│ │ │ │ │ ├── ChatApplication.java
│ │ │ │ │ ├── ClientGUIReceiver.java
│ │ │ │ │ ├── ClientReceiver.java
│ │ │ │ │ ├── MainContainer.java
│ │ │ │ │ └── ServerThread.java
│ │ │ │ └── server
│ │ │ │ ├── ClientThread.java
│ │ │ │ ├── Main.java
│ │ │ │ └── Server.java
│ │ │ └── module-info.java
│ │ └── resources
│ │ └── com
│ │ └── client
│ │ └── javachatapplication
│ │ └── view.fxml
│ └── module-info.java
└── target
├── classes
│ └── module-info.class
└── test-classes
运行应用程序时遇到错误
Error occurred during initialisation of boot layer
java.lang.LayerInstantiationException: Package jakarta.websocket.server in both module jakarta.websocket and module org.apache.tomcat.embed.websocket
花了一整夜的时间,通过包含单个依赖项解决了循环依赖或冲突依赖。请删除 embd tomcat 并包含单一依赖项。感谢大家的支持
在我的 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.wsclient</groupId>
<artifactId>wsclient</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>simplewsClient</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>21.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.glassfish.tyrus</groupId>
<artifactId>tyrus-client</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-api</artifactId>
<version>10.1.17</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-coyote</artifactId>
<version>10.1.17</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-util-scan</artifactId>
<version>10.1.17</version>
</dependency>
<dependency>
<groupId>jakarta.servlet.jsp</groupId>
<artifactId>jakarta.servlet.jsp-api</artifactId>
<version>3.1.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.el</groupId>
<artifactId>jakarta.el-api</artifactId>
<version>5.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-websocket</artifactId>
<version>10.1.17</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.3</version>
<configuration>
<mainClass>com.wsclient.App</mainClass>
</configuration>
</plugin>
</plugins>
</build>