Java 17 module project (maven), when reading Json NoClassDefFoundError: jakarta/json/JsonConfig$KeyStrategy
Java 17 module project (maven), when reading Json NoClassDefFoundError: jakarta/json/JsonConfig$KeyStrategy
这不是我的第一个基于模块的项目,但我对它的工作原理很不了解,我确信这是我的问题。目前,Project Jigsaw 对我来说就像是雾里看花。
如有任何帮助,我们将不胜感激。
这里是异常发生的地方:
result.payload().ifPresent(payloadString -> {
final var jsonReader = Json.createReader(new StringReader(payloadString));
final var jsonObject = jsonReader.readObject(); <== error here
jsonReader.close();
我的模块-info.java
module com.mymodule.pocclient {
requires javafx.controls;
requires javafx.fxml;
requires jcip.annotations;
requires java.logging;
requires org.controlsfx.controls;
requires com.dlsc.formsfx;
requires jakarta.json.bind;
requires jakarta.json;
requires org.eclipse.yasson;
requires org.eclipse.parsson;
requires static lombok;
requires jjwt.api;
requires com.mymodule.cryptography;
opens com.mymodule.pocclient.controllers to javafx.fxml;
opens com.mymodule.pocclient.model to javafx.base, org.eclipse.yasson;
opens com.mymodule.pocclient to javafx.fxml;
opens com.mymodule.pocclient.network to org.eclipse.parsson;
exports com.mymodule.pocclient;
exports com.mymodule.pocclient.controllers;
}
异常:
java.lang.NoClassDefFoundError: jakarta/json/JsonConfig$KeyStrategy
at org.eclipse.parsson@1.1.0/org.eclipse.parsson.JsonObjectBuilderImpl$DuplicateStrategy.<clinit>(JsonObjectBuilderImpl.java:373)
at org.eclipse.parsson@1.1.0/org.eclipse.parsson.JsonObjectBuilderImpl.<init>(JsonObjectBuilderImpl.java:59)
at org.eclipse.parsson@1.1.0/org.eclipse.parsson.JsonParserImpl.getObject(JsonParserImpl.java:171)
at org.eclipse.parsson@1.1.0/org.eclipse.parsson.JsonReaderImpl.readObject(JsonReaderImpl.java:103)
at com.lifelenz.poclifelenzclient/com.mymodule.pocclient.controllers.LoginController.lambda$processAuthenticatedUser[=12=](LoginController.java:121)
我的 pom 文件中的依赖项(不确定有多少相关)
<dependency>
<groupId>com.lifelenz.jmsa</groupId>
<artifactId>cryptography</artifactId>
<version>0.1.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.parsson</groupId>
<artifactId>parsson</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.3.0.Final</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.json.bind</groupId>
<artifactId>jakarta.json.bind-api</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.eclipse</groupId>
<artifactId>yasson</artifactId>
<version>3.0.0-RC2</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>jakarta.json</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
<version>0.11.5</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>0.11.5</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId> <!-- or jjwt-gson if Gson is preferred -->
<version>0.11.5</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>net.jcip</groupId>
<artifactId>jcip-annotations</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.controlsfx</groupId>
<artifactId>controlsfx</artifactId>
<version>11.1.1</version>
</dependency>
<dependency>
<groupId>com.dlsc.formsfx</groupId>
<artifactId>formsfx-core</artifactId>
<version>11.5.0</version>
<exclusions>
<exclusion>
<groupId>org.openjfx</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</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>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>18.0.1</version>
</dependency>
删除以下依赖项解决了问题。
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>jakarta.json</artifactId>
<version>2.0.1</version>
</dependency>
我认为它与 parsson 冲突。
这不是我的第一个基于模块的项目,但我对它的工作原理很不了解,我确信这是我的问题。目前,Project Jigsaw 对我来说就像是雾里看花。 如有任何帮助,我们将不胜感激。
这里是异常发生的地方:
result.payload().ifPresent(payloadString -> {
final var jsonReader = Json.createReader(new StringReader(payloadString));
final var jsonObject = jsonReader.readObject(); <== error here
jsonReader.close();
我的模块-info.java
module com.mymodule.pocclient {
requires javafx.controls;
requires javafx.fxml;
requires jcip.annotations;
requires java.logging;
requires org.controlsfx.controls;
requires com.dlsc.formsfx;
requires jakarta.json.bind;
requires jakarta.json;
requires org.eclipse.yasson;
requires org.eclipse.parsson;
requires static lombok;
requires jjwt.api;
requires com.mymodule.cryptography;
opens com.mymodule.pocclient.controllers to javafx.fxml;
opens com.mymodule.pocclient.model to javafx.base, org.eclipse.yasson;
opens com.mymodule.pocclient to javafx.fxml;
opens com.mymodule.pocclient.network to org.eclipse.parsson;
exports com.mymodule.pocclient;
exports com.mymodule.pocclient.controllers;
}
异常:
java.lang.NoClassDefFoundError: jakarta/json/JsonConfig$KeyStrategy
at org.eclipse.parsson@1.1.0/org.eclipse.parsson.JsonObjectBuilderImpl$DuplicateStrategy.<clinit>(JsonObjectBuilderImpl.java:373)
at org.eclipse.parsson@1.1.0/org.eclipse.parsson.JsonObjectBuilderImpl.<init>(JsonObjectBuilderImpl.java:59)
at org.eclipse.parsson@1.1.0/org.eclipse.parsson.JsonParserImpl.getObject(JsonParserImpl.java:171)
at org.eclipse.parsson@1.1.0/org.eclipse.parsson.JsonReaderImpl.readObject(JsonReaderImpl.java:103)
at com.lifelenz.poclifelenzclient/com.mymodule.pocclient.controllers.LoginController.lambda$processAuthenticatedUser[=12=](LoginController.java:121)
我的 pom 文件中的依赖项(不确定有多少相关)
<dependency>
<groupId>com.lifelenz.jmsa</groupId>
<artifactId>cryptography</artifactId>
<version>0.1.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.parsson</groupId>
<artifactId>parsson</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.3.0.Final</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.json.bind</groupId>
<artifactId>jakarta.json.bind-api</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.eclipse</groupId>
<artifactId>yasson</artifactId>
<version>3.0.0-RC2</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>jakarta.json</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
<version>0.11.5</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>0.11.5</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId> <!-- or jjwt-gson if Gson is preferred -->
<version>0.11.5</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>net.jcip</groupId>
<artifactId>jcip-annotations</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.controlsfx</groupId>
<artifactId>controlsfx</artifactId>
<version>11.1.1</version>
</dependency>
<dependency>
<groupId>com.dlsc.formsfx</groupId>
<artifactId>formsfx-core</artifactId>
<version>11.5.0</version>
<exclusions>
<exclusion>
<groupId>org.openjfx</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</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>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>18.0.1</version>
</dependency>
删除以下依赖项解决了问题。
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>jakarta.json</artifactId>
<version>2.0.1</version>
</dependency>
我认为它与 parsson 冲突。