[英]Grizzy/Jersey: POJO-mapping does not work with Maven one-jar
我在github上创建了一个简单的项目 (请参见那里的资源)。
如果将项目作为Eclipse中的Maven项目导入并运行,则可以卷曲XML / JSON资源。
如果我使用mvn package
创建一个jar,然后运行它,则无法卷曲XML / JSON资源。 我收到以下错误:
Caused by: com.sun.jersey.api.MessageException: A message body writer for Java class de.dennis_boldt.resources.User, and Java type class de.dennis_boldt.resources.User, and MIME media type application/xml was not found
Caused by: com.sun.jersey.api.MessageException: A message body writer for Java class de.dennis_boldt.resources.User, and Java type class de.dennis_boldt.resources.User, and MIME media type application/json was not found
我想念什么吗? 也许是Maven依赖项?
解决方案是使用maven-shade-plugin
:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>package.Main</Main-Class>
<Build-Number>1</Build-Number>
</manifestEntries>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.