2017-06-15 44 views
1

我尝试在NetBeans中构建maven-project。在项目中,我使用jersey-media-json-jackson。我的依赖关系看起来像jersey-media-json-jackson不包含在jar中

<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. 

同样的例外出现在IDE时,我的评论球衣,媒体JSON - 杰克逊的依赖。在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> 

如何解决我的问题

我的构建块?

+1

我希望你在运行'罐子与 - dependencies'而不是缺省罐子生成。 –

回答

0

由于泽西岛自动发现并注册功能的方式,可能会发生这种情况。将所有内容放入胖罐中都会导致此自动发现和注册问题,您可能需要手动完成。

参考this回答一个非常类似的问题,只有在你的情况进行登记新泽西州的杰克逊功能的声明很可能是

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

谢谢!你的链接很有帮助。使用maven-shade-plugin修复了我的问题。 – SpeakWind