Maven的Jersey问题-Shade插件

Maven的Jersey问题-Shade插件

问题描述:

我的问题非常类似于:球衣例外情况仅在将药液组装到一个罐子中时抛出

My problem is very similar to: Jersey exception only thrown when depencencies assembled into a single jar

我运行我的应用程序(嵌入式码头+球衣),一切正常.当我尝试创建可执行JAR时,出现错误:

I run my application (jetty embedded + jersey) and everything works. When i try to create a executable JAR i get the error:

org.glassfish.jersey.message.internal.WriterInterceptorExecutor $ TerminalWriterInterceptor aroundWriteTo 严重:找不到针对媒体type = application/json,type = class

org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor aroundWriteTo GRAVE: MessageBodyWriter not found for media type=application/json, type=class

我的POM.XML:

<plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.3</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>server.application.DeepDig</mainClass>
                                </transformer>
                            </transformers>

                            <filters>
                                <!-- filter to address "Invalid signature file" issue - see https://*.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>
        </plugins>

前一段时间,我遇到了同样的问题.问题在于服务文件未合并.以下对我有用:

I ran into the same problem a while ago. The problem is with the services files not getting merged. The following works for me:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <configuration>
                <transformers>
                    <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                        <mainClass>Foo</mainClass>
                    </transformer>
                    <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
                </transformers>
            </configuration>
        </plugin>

此问题的根本原因是,与泽西岛相关的多个jar均在META-INF中包含一个服务"文件,该文件包含让泽西岛正常工作的元数据.默认情况下,shadow插件会选择这些文件之一,并将其​​包含在胖罐中.由于不包括其他文件中的元数据,因此Jersey无法正常工作.

The root cause of the problem is that each of several Jersey-related jars contain a "services" file in META-INF that contains metadata for Jersey to work properly. By default, the shade plugin picks one of these files and includes it in the fat jar. Because metadata from the other files is not included, Jersey doesn't work properly.

此修补程序包括在调用shade插件时的其他转换器.该转换器将数据合并到各个文件中,而不仅仅是选择其中一个文件.这样,所有必需的元数据都包含在胖子罐中,并且Jersey可以正常工作.

This fix includes the additional transformer when the shade plugin is invoked. This transformer merges the data in the various files rather than just picking one of the files. In this way, all of the required metadata is included in the fat jar and Jersey works properly.