泽西-媒体-JSON-杰克逊不包括在 JAR 中



我尝试在NetBeans中构建maven-project。在项目中,我使用jersey-media-json-jackson。我的依赖项看起来像那样

<dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-json-jackson</artifactId>
    <version>2.23.1</version>
</dependency>

如果我在 IDE 中运行项目,一切正常。但是如果我使用依赖项构建项目并运行生成的 jar 文件,则会出现以下错误

org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor aroundWriteTo
SEVERE: MessageBodyWriter not found for media type=application/json, type=class com.ats.orion.client.model.req.UpdateContextRequest, genericType=class com.ats.orion.client.model.req.UpdateContextRequest.
Exception in thread "main" org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=application/json, type=class com.ats.orion.client.model.req.UpdateContextRequest, genericType=class com.ats.orion.client.model.req.UpdateContextRequest.

当我评论jersey-media-json-jackson依赖项时,IDE中会出现相同的异常。

我在pom中的构建块.xml

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.ats.test.App</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id> 
                        <phase>package</phase> 
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

如何解决我的问题?

这可能是由于泽西岛自动发现和注册要素的方式而发生的。将所有东西都放入一个胖罐子中可能会导致此自动发现和注册出现问题,您可能需要手动执行此操作。

将此答案引用到一个非常相似的问题,只有在您的情况下,注册泽西岛杰克逊功能的声明可能是

jerseyServlet.setInitParameter(
                "jersey.config.server.provider.classnames",
                "org.glassfish.jersey.jackson.JacksonFeature"); 

最新更新