只有当依赖性组装成一个罐子时才会抛出泽西异常 [英] Jersey exception only thrown when depencencies assembled into a single jar

查看:89
本文介绍了只有当依赖性组装成一个罐子时才会抛出泽西异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个嵌入Jetty w / Jersey的服务器。当我从Eclipse执行时,一切都很棒。但是,如果我使用Maven的程序集将我的服务器和所有依赖项组装到一个jar中:单个目标,我会得到一个例外:

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 write
SEVERE: A message body writer for Java class com.acme.server.webservice.
exception.WebServiceFailure, and Java type class com.acme.server.webserv
ice.exception.WebServiceFailure, and MIME media type application/json was not fo
und
Sep 26, 2012 5:35:59 PM com.sun.jersey.spi.container.ContainerResponse write
SEVERE: The registered message body writers compatible with the MIME media type
are:
*/* ->
  com.sun.jersey.server.impl.template.ViewableMessageBodyWriter

17:35:59.372 [qtp184245201-22 - /] ERROR o.a.h.ReflectorServletProcessor - onReq
uest()
javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException: A mess
age body writer for Java class com.acme.server.webservice.exception.WebS
erviceFailure, 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(ContainerRespons
e.java:285) ~[vma-server-0.0.1-SNAPSHOT-jar-with-dependencies.jar:na]
        at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequ
est(WebApplicationImpl.java:1457) ~[server-0.0.1-SNAPSHOT-jar-with-dependenc
ies.jar:na]

...

完整的跟踪在这里,如果它有用:
https://gist.github.com/3790817

The full trace is here, if it's useful: https://gist.github.com/3790817

Maven在创建jar-with时不会抛出任何错误-dependencies。

Maven throws no errors while creating the jar-with-dependencies.

我是Maven的新手和Java的部署,我真的不确定如何继续调试。

I'm a novice with Maven and deployment of Java, and I'm really not sure how to proceed with debugging.

此外,虽然我需要解决这个问题,但我也很欣赏任何建议的解决方法,因为我需要尽快生成我的服务器的可执行演示版本Pointy- Haired Boss(tm)可以在没有Eclipse的情况下执行。

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.

解决方案:

基于在Pavel的回答中,我删除了maven-assemly-plugin,转而使用maven-shade-plugin。这是适用于我的阴影配置:

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使用META-INF /服务机制来发现它的组件和程序集:single可能只是将所有内容复制到单个jar中,覆盖已经存在的文件但是META-INF / services文件(s)需要加强。

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.

尝试使用jersey-bundle( com.sun.jersey:jersey-bundle:1.14 )或修复你的程序集设置(或找到另一个插件来做得更好)。

Try using jersey-bundle (com.sun.jersey:jersey-bundle:1.14) or fix your assembly settings (or find another plugin to do it better).

这篇关于只有当依赖性组装成一个罐子时才会抛出泽西异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆