[英]Maven dependencies wrong Jersey class chosen at runtime
我有一個帶有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.1
,而azure-serviceruntime
包含jersey-core:1.13
,它們都包含javax.ws.rs.core
包中的類Application
。
在Eclipse中搜索Application
類型顯示以下內容(以澄清):
問題是在運行時使用了錯誤的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 shade重新定位類/包但沒有任何成功。
如何告訴Java使用最新的Application
類?
我終於搞定了。 我進一步研究了它在Windows而不是Linux上工作的事實,區別在於我在Windows上使用OracleJDK而在Linux上使用openJDK。
所以我在Linux上使用OracleJDK作為我的項目,現在它可以工作了。
我認為你最好的選擇是使用依賴項排除從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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.