mvn软件包后缺少resteasy提供程序 [英] resteasy providers missing after mvn package

查看:98
本文介绍了mvn软件包后缺少resteasy提供程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一些使用resteasy库的代码.

I have written some code that uses some resteasy libraries.

该代码在Eclipse中运行良好,但是当使用maven shade插件作为fat-jar构建执行时,会产生异常.

The code works fine in Eclipse but produces exceptions when excecuted as fat-jar build with the maven shade plugin.

原因:在META-INF/services/javax.ws.rs.ext.Providers下创建的jar中,仅列出了resteasy-client中的提供者. 但是,我还需要resteasy-jackson2-provider和resteasy-jaxrs的提供程序.

The reason: in the created jar under META-INF/services/javax.ws.rs.ext.Providers only the providers from resteasy-client are listed. I however also need the providers from resteasy-jackson2-provider and from resteasy-jaxrs.

我认为问题可能是,所有3个库(resteasy-client,resteasy-jackson2-provider,resteasy-jaxrs)都使用同名文件列出其提供程序(META-INF/services/javax.ws.rs .ext.Providers). 那么,也许maven会覆盖一个库中的提供者列表,并覆盖其他库中的提供者列表?

I think the issue might be, that all 3 libraries (resteasy-client, resteasy-jackson2-provider, resteasy-jaxrs) use an identically named file to list their providers (META-INF/services/javax.ws.rs.ext.Providers). So maybe maven overwrites the provider list from one library with the list from the others?

我的pom.xml看起来像这样:

My pom.xml looks like this:

<properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
  <dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-client</artifactId>
    <version>3.6.1.Final</version>
  </dependency>
  <dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jackson2-provider</artifactId>
    <version>3.6.1.Final</version>
  </dependency>
</dependencies>

<build>
  <plugins>
    <plugin>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.3</version>
      <configuration>
        <source>1.8</source>
        <target>1.8</target>
      </configuration>
    </plugin>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-shade-plugin</artifactId>
      <version>3.2.0</version>
      <executions>
        <execution>
          <phase>package</phase>
          <goals>
            <goal>shade</goal>
          </goals>
          <configuration>
            <filters>
              <filter>
                <artifact>*:*</artifact>
                <excludes>
                  <exclude>META-INF/*.SF</exclude>
                  <exclude>META-INF/*.DSA</exclude>
                  <exclude>META-INF/*.RSA</exclude>
                </excludes>
              </filter>
            </filters>
            <transformers>
              <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                <manifestEntries>
                  <Main-Class>playarounds.ServiceMainClass</Main-Class>
                </manifestEntries>
              </transformer>
            </transformers>
            <artifactSet/>
            <outputFile>${project.build.directory}/${project.artifactId}-${project.version}-fat.jar</outputFile>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

推荐答案

好,我找到了解决方法.

Ok, i found the solution.

Maven阴影插件允许您强制附加名称相同的文件...

Maven shade plugin allows you to force append files that are identically named...

所以pom.xml中滞后的maven-shade-plugin是:

So what the maven-shade-plugin in the pom.xml lags is:

<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
  <resource>META-INF/services/javax.ws.rs.ext.Providers</resource>
</transformer>

https://maven.apache. org/plugins/maven-shade-plugin/examples/resource-transformers.html#AppendingTransformer

这篇关于mvn软件包后缺少resteasy提供程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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