要添加什么 Jersey 依赖项以避免 jersey.repackaged.com.google.common.collect.Maps 的 NoClassDefFoundError

2022-01-21 00:00:00 java jersey

我正在尝试运行一个扩展 JerseyTest 的测试,但运行它时我得到一个:

I'm trying to run a a test that extends JerseyTest but when running it I'm getting a:

java.lang.NoClassDefFoundError: jersey/repackaged/com/google/common/collect/Maps

知道我缺少什么依赖项吗?我在 pom.xml 中包含了以下球衣工件,并且 jersey.version 是 2.5.1:

Any idea what dependency I'm missing? I've included the following jersey artifacts in my pom.xml and jersey.version is 2.5.1:

    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet</artifactId>
        <version>${jersey.version}</version>
    </dependency>

    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-client</artifactId>
        <version>${jersey.version}</version>
    </dependency>        

    <dependency>
        <groupId>com.sun.jersey.jersey-test-framework</groupId>
        <artifactId>jersey-test-framework-core</artifactId>
        <version>1.18</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.glassfish.jersey.test-framework.providers</groupId>
        <artifactId>jersey-test-framework-provider-grizzly2</artifactId>
        <version>2.6</version>
        <scope>test</scope>
    </dependency>

推荐答案

你需要:

<dependency>
  <groupId>org.glassfish.jersey.bundles.repackaged</groupId>
  <artifactId>jersey-guava</artifactId>
  <version>2.6</version>
</dependency>

来自 http://blog.dejavu.sk/2014/02/21/jersey-2-6-has-been-released-new-and-noteworthy/

Jersey,从 JAX-RS 2.0 的 2.6 版和 JAX-RS 1.1 的 1.18.1 版开始,不再将 Guava 和 ASM 库传递到您的应用程序中.这意味着即使我们仍在内部使用它们,您也可以使用这些库的不同版本.这两个库中的类已重新打包,分别是 jersey.repackaged.com.google.commonjersey.repackaged.objectweb.asm,并缩小以减少占用空间.ASM 5 现在是 jersey-server 核心模块的一部分,我们为 Guava 创建了一个单独的捆绑模块 jersey-guava 因为这种依赖被广泛用于多个 Jersey 模块中.

Jersey, from versions 2.6 for JAX-RS 2.0 and 1.18.1 for JAX-RS 1.1, no longer transitively brings Guava and ASM libraries to your application. This means that even when we still use them internally you can use different versions of these libraries. Classes from both of these libraries has been repackaged, jersey.repackaged.com.google.common and jersey.repackaged.objectweb.asm respectively, and shrinked to lower the footprint. ASM 5 is now part of jersey-server core module and for Guava we’ve created a separate bundle module jersey-guava as this dependency is widely used in multiple Jersey modules.

您使用的是 Jersey 2.6 jersey-test-framework-provider-grizzly2.

You're using the Jersey 2.6 jersey-test-framework-provider-grizzly2.

相关文章