27

Jetty w/Jersey を組み込んだサーバーを作成しています。Eclipse から実行すると、すべてがうまくいきます。ただし、Maven の assembly:single ゴールを使用してサーバーとすべての依存関係を単一の jar にアセンブルすると、例外が発生します。

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

jar-with-dependencies の作成中に、Maven はエラーをスローしません。

私は Maven と Java のデプロイの初心者であり、デバッグの進め方がよくわかりません。

また、この問題を解決する必要がある一方で、Eclipse なしで Pointy-Haired Boss (tm) を実行できるサーバーの実行可能なデモをできるだけ早く作成する必要があるため、提案された回避策もあれば幸いです。

解決:

Pavel の回答に基づいて、maven-shade-plugin を優先して maven-assemly-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>
                        <!--  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>
4

2 に答える 2

24

ジャージージャーを正しくマージしていません。

Jersey 1.xは、META-INF / servicesメカニズムを使用して、そのコンポーネントとアセンブリを検出します。singleは、おそらくすべてを単一のjarにコピーし、既存のファイルをオーバーライドしますが、META-INF/servicesファイルは連結する必要があります。

jersey-bundle(com.sun.jersey:jersey-bundle:1.14)を使用するか、アセンブリ設定を修正してみてください(または別のプラグインを見つけて改善してください)。

于 2012-09-27T13:02:09.023 に答える
1

あなたのポンを投稿していただけますか?

一部の依存関係を提供済みとしてマークしますか? 一部の jar は Web コンテナー (Tomcat など) によって提供されることになっているため、スタンドアロン アプリと Web アプリのビルドはまったく異なります。

コンテナはアプリに「埋め込まれている」ため(コンテナ内のアプリではありません)、これらの依存関係を正しく管理していない可能性があります。

于 2012-09-27T08:28:42.650 に答える