解决方案:根据 Pavel 的回答,我放弃了 maven-assemly-plugin 以支持 maven-shade-plugin.这是对我有用的阴影配置: <groupId>org.apache.maven.plugins</groupId><artifactId>maven-shade-plugin</artifactId><version>2.0</version><执行><执行><phase>包</phase><目标><目标>阴影</目标></目标><配置><变形金刚><!-- 使用转换器来处理 META-INF/services 的合并 - 参见 http://java.net/jira/browse/JERSEY-440?focusedCommentId=14822&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#action_14822 --><变压器implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/></变形金刚><过滤器><!-- 过滤以解决无效签名文件"问题-请参阅 http://stackoverflow.com/a/6743609/589215--><过滤器><神器>*:*</神器><排除><exclude>META-INF/*.SF</exclude><exclude>META-INF/*.DSA</exclude><exclude>META-INF/*.RSA</exclude></排除></过滤器></过滤器></配置></执行></执行></插件> 解决方案 您没有正确合并 Jersey jar.Jersey 1.x 使用 META-INF/services 机制来发现它的组件和程序集:single 可能只是将所有内容复制到单个 jar 中,覆盖已经存在的文件但 META-INF/services 文件需要连接.尝试使用 jersey-bundle (com.sun.jersey:jersey-bundle:1.14) 或修复您的程序集设置(或找到另一个插件来做得更好).I'm writing a server that embeds Jetty w/ Jersey. When I execute from Eclipse, everything is great. However, if I assemble my server and all dependencies into a single jar using Maven's assembly:single goal, I get an exception:Sep 26, 2012 5:35:59 PM com.sun.jersey.spi.container.ContainerResponse writeSEVERE: A message body writer for Java class com.acme.server.webservice.exception.WebServiceFailure, and Java type class com.acme.server.webservice.exception.WebServiceFailure, and MIME media type application/json was not foundSep 26, 2012 5:35:59 PM com.sun.jersey.spi.container.ContainerResponse writeSEVERE: The registered message body writers compatible with the MIME media typeare:*/* -> com.sun.jersey.server.impl.template.ViewableMessageBodyWriter17:35:59.372 [qtp184245201-22 - /] ERROR o.a.h.ReflectorServletProcessor - onRequest()javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException: A message body writer for Java class com.acme.server.webservice.exception.WebServiceFailure, and Java type class com.acme.server.webservice.exception.WebServiceFailure, and MIME media type application/json was not found at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:285) ~[vma-server-0.0.1-SNAPSHOT-jar-with-dependencies.jar:na] at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1457) ~[server-0.0.1-SNAPSHOT-jar-with-dependencies.jar:na]...The full trace is here, if it's useful:https://gist.github.com/3790817Maven throws no errors while creating the jar-with-dependencies.I'm a novice with Maven and deployment of Java, and I'm really not sure how to proceed with debugging.Also, while I need to solve this issue I'd also appreciate any suggested work-arounds as I need to produce an executable demo of my server ASAP that a Pointy-Haired Boss (tm) can execute without Eclipse.Solution:Based on Pavel's answer, I dropped the maven-assemly-plugin in favor of maven-shade-plugin. Here's the shade configuration that worked for me: <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> <!-- use transformer to handle merge of META-INF/services - see http://java.net/jira/browse/JERSEY-440?focusedCommentId=14822&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#action_14822 --> <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" /> </transformers> <filters> <!-- filter to address "Invalid signature file" issue - see http://stackoverflow.com/a/6743609/589215--> <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> 解决方案 You are not merging Jersey jars correctly.Jersey 1.x uses META-INF/services mechanism to discover its components and assembly:single probably just copies everything into single jar, overriding already present files BUT META-INF/services file(s) needs to be CONCATENATED.Try using jersey-bundle (com.sun.jersey:jersey-bundle:1.14) or fix your assembly settings (or find another plugin to do it better). 这篇关于Jersey 异常仅在依赖组合成单个 jar 时抛出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-06 05:12