当来自 fatjar 运行 时找不到 MessageBodyWriter 错误
MessageBodyWriter not found Error when running from fatjar
只有当来自 fatjar 的 运行、mvn run:java
按预期工作时,我才会收到此错误。
SEVERE: MessageBodyWriter not found for media type=application/json, type=class com.example.Greeting, genericType=class com.example.Greeting.
我正在使用 moxy 进行 json 处理。我试过杰克逊,没有任何区别。尝试使用 grizzly 而不是 o jetty,同样的问题。
这是我的 pom 依赖项:
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-jetty-http</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.test-framework</groupId>
<artifactId>jersey-test-framework-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-jetty</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
</dependencies>
Shade 插件配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<id>shade</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<!--<minimizeJar>true</minimizeJar>-->
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.example.http.JettyHttpServer</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
球衣版本为 2.30.1。
谢谢!
编辑
org.glassfish.jersey.internal.spi.AutoDiscoverable的内容不包括org.glassfish.jersey.moxy.json.internal.MoxyJsonAutoDiscoverable
org.glassfish.jersey.logging.LoggingFeatureAutoDiscoverable
org.glassfish.jersey.internal.config.ExternalPropertiesAutoDiscoverable
根据 应该是这样。我该如何解决?
尝试在代码上显式加载您需要的依赖项,而不是依赖于自动发现,在 Jersey 上注册它们。
fat jar 插件会尝试分析您的代码并查看正在使用的内容和未使用的内容,因此它可以排除未使用的引用并生成较小的 jar。自动发现的问题在于,由于没有明确引用某些 类,阴影插件可以认为它们没有被使用,因此可以将其删除。
我认为有一种方法可以强制将它们包含在插件配置中,但我不记得那个配置来自内存,你必须在文档中搜索它。
只有当来自 fatjar 的 运行、mvn run:java
按预期工作时,我才会收到此错误。
SEVERE: MessageBodyWriter not found for media type=application/json, type=class com.example.Greeting, genericType=class com.example.Greeting.
我正在使用 moxy 进行 json 处理。我试过杰克逊,没有任何区别。尝试使用 grizzly 而不是 o jetty,同样的问题。
这是我的 pom 依赖项:
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-jetty-http</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.test-framework</groupId>
<artifactId>jersey-test-framework-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-jetty</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
</dependencies>
Shade 插件配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<id>shade</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<!--<minimizeJar>true</minimizeJar>-->
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.example.http.JettyHttpServer</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
球衣版本为 2.30.1。
谢谢!
编辑
org.glassfish.jersey.internal.spi.AutoDiscoverable的内容不包括org.glassfish.jersey.moxy.json.internal.MoxyJsonAutoDiscoverable
org.glassfish.jersey.logging.LoggingFeatureAutoDiscoverable
org.glassfish.jersey.internal.config.ExternalPropertiesAutoDiscoverable
根据
尝试在代码上显式加载您需要的依赖项,而不是依赖于自动发现,在 Jersey 上注册它们。
fat jar 插件会尝试分析您的代码并查看正在使用的内容和未使用的内容,因此它可以排除未使用的引用并生成较小的 jar。自动发现的问题在于,由于没有明确引用某些 类,阴影插件可以认为它们没有被使用,因此可以将其删除。
我认为有一种方法可以强制将它们包含在插件配置中,但我不记得那个配置来自内存,你必须在文档中搜索它。