Monday 15 April 2013

java - Jersey problems with Maven - Shade Plugin -


itemprop = "text">

My problem is similar to many:

I have my application (JT embedded + jersey) and everything Run works. When I try to make an executable jar, I get an error:

org.glassfish.jersey.message.internal.WriterInterceptorExecutor $ TerminalWriterInterceptor aroundWriteTo Grave: MessageBodyWriter Media Type = not for application / json Found, type = class

my POM.XML:

   & Lt; Version & gt; 2.3 & lt; / Edition & gt; & Lt; Hanging & gt; & Lt; Execution & gt; & Lt; Step & gt; Package & lt; / Step & gt; & Lt; Goals & gt; & Lt; Goal & gt; Shadow & lt; / Target & gt; & Lt; / Targets & gt; & Lt; Configuration & gt; & Lt; Transformer & gt; & Lt; Transformer implementation = "org.apache.maven.plugins.shade.resource.ManifestResourceTransformer" & gt; & Lt; MainClass & gt; Server.application.DeepDig & lt; / MainClass & gt; & Lt; / Transformer & gt; & Lt; / Transformer & gt; & Lt; Filter & gt; & Lt ;! - Filter "Invalid signature file" to solve the problem - https://stackoverflow.com/a/6743609/589215 - & gt; See. & Lt; Filter & gt; & Lt; Artifact & gt; *: * & Lt; / Artifact & gt; & Lt; Exclude & gt; & Lt; Out to & gt; META-INF / * SF & lt; / Exclude & gt; & Lt; Out to & gt; META-INF / * DSA & lt; / Exclude & gt; & Lt; Out to & gt; META-INF / * RSA & lt; / Exclude & gt; & Lt; / Not included & gt; & Lt; / Filter & gt; & Lt; / Filters & gt; & Lt; / Configuration & gt; & Lt; / Execution & gt; & Lt; / Hanging & gt; & Lt; / Plugin & gt; & Lt; / Plugins & gt;  

After

I encountered the same problem some time ago. The problem is with services files that are not merged, the following work for me:

  & lt; Plugin & gt; & Lt; Group & gt; Org.apache.maven.plugins & lt; / Group & gt; & Lt; ArtifactId & gt; Maven-shadow-plugin & lt; / ArtifactId> & Lt; Configuration & gt; & Lt; Transformer & gt; & Lt; Transformer implementation = "org.apache.maven.plugins.shade.resource.ManifestResourceTransformer" & gt; & Lt; MainClass & gt; Foo & lt; / MainClass & gt; & Lt; / Transformer & gt; & Lt; Transformer implementation = "org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" /> & Lt; / Transformer & gt; & Lt; / Configuration & gt; & Lt; / Plugin & gt; The root cause of the problem is that in many jersey-related jars, there is a "services" file in Meta-INF, in which the jersey requires metadata to work properly. By default, the shadow plugin chooses one of these files and incorporates it into a fat jar because the other files do not include metadata, jersey does not work properly. 

This fix contains an additional transformer when the shadow plugin is applied. This transformer merges data into different files instead of just selecting one of the files, thus, all the required metadata in the desired jar and jersey contains.


No comments:

Post a Comment