2017-06-15 45 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