gpt4 book ai didi

java - Maven 依赖项在运行时选择了错误的 Jersey 类

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:49:47 24 4
gpt4 key购买 nike

我有一个带有 Maven 和 Tomcat 的 Java Servlet 项目,其中包含以下两个依赖项(以及许多其他依赖项):

<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.25.1</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-serviceruntime</artifactId>
<version>0.6.0</version>
</dependency>

jersey-server 包含javax.ws.rs-api:2.0.1azure-serviceruntime 包含jersey- core:1.13 都包含 javax.ws.rs.core 包中的类 Application

在 Eclipse 中搜索 Application 类型显示以下内容(澄清): The two Application classes

问题是在运行时使用了错误的 Application 类,这导致在启动 Tomcat 时出现以下错误:

java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;

对于每个 servlet。

我尝试从 azure-serviceruntime 中排除 jersey-core 但随后 servlet 似乎根本没有加载。我还尝试将 javax.ws.rs-api 添加为直接依赖项,但这也没有用。最无法解释的部分是它可以在 Windows 上运行但不能在 Linux 上运行......我还尝试使用 Maven 阴影重新定位类/包,但没有成功。

如何告诉 Java 使用最新的 Application 类?

最佳答案

我认为最好的选择是使用 dependency exclusion从 azure-serviceruntime 依赖项中排除 jersey-core:1.13:

<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.25.1</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-serviceruntime</artifactId>
<version>0.6.0</version>
<exclusions>
<exclusion>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-core</artifactId>
</exclusion>
</exclusions>
</dependency>

关于java - Maven 依赖项在运行时选择了错误的 Jersey 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45556552/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com