【问题标题】:jersey-media-json-jackson not included in jarjersey-media-json-jackson 不包含在 jar 中
【发布时间】:2017-11-18 05:27:58
【问题描述】:

我尝试在 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>

如何解决我的问题?

【问题讨论】:

  • 我希望你运行的是jar-with-dependencies而不是默认生成的jar。

标签: java json maven


【解决方案1】:

这可能是由于 Jersey 自动发现和注册功能的方式。将所有内容放入胖罐中可能会导致此自动发现和注册出现问题,您可能必须手动进行。

参考this回答一个非常相似的问题,只有在你的情况下,注册泽西杰克逊功能的声明可能是

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

【讨论】:

  • 谢谢!您的链接很有帮助。使用 maven-shade-plugin 解决了我的问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-28
  • 2012-01-23
  • 1970-01-01
  • 2011-08-13
  • 2015-03-10
  • 1970-01-01
相关资源
最近更新 更多