Jersey problems with Maven - Shade Plugin

≯℡__Kan透↙ 提交于 2019-12-04 05:28:50

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>

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!