java - 为什么不同组织的javax.annotation不同

标签 java jetty guava

我在我的java项目中使用guava和jetty,同时我发现了一个奇怪的问题。 在guava中,它取决于javax.annotation有这么多类,而在jetty中javax.annotation比guava中少。他们有什么区别。

此外,jetty中的javax.annotation是有签名的,而guava中的javax.annotation是没有签名的。当jvm从guava.jar和jetty.jar中的javax.annotation包中加载类时,会抛出SecurityException,导致一个包已签名,而其他包未签名。

那么,guava.jar 和 jetty.jar 之间的 javax.annotation 包的真正区别是什么?

Guava 中的包: no sign and has lot of class

jetty 的包裹: signed and has little class

最佳答案

javax.annotations 包中有不同的库提供类型。 Guava 使用的是来自(现已废弃)JSR-305 proposal 的 JAR。 。在 Maven 中,这是 com.google.code.findbugs:jsr305:1.3.9 .

另一个 JAR 似乎是 org.eclipse.jetty.orbit:javax.annotation:1.1.0.v201108011116 。目前尚不清楚该 JAR 来自何处,它似乎是在 2011 年上传的,此后从未更新过。

这两个 JAR 之间的冲突似乎是 a well-known one .

看来此 JAR 的“依赖项”已添加到 Guava release 13 中,但该版本的发行说明说:

Made findbugs a provided dependency to avert dep conflicts when using findbugs 2.0. The side-effect of this change is that projects which relied upon Guava to grant access to the JSR-305 annotations "for free" will break unless they provide their own direct dependency on that jar (or an equivalent). Projects should always have been directly depending on JSR-305 (per maven best-practice), but this change makes that should into a must.

因此,据我了解,Guava 实际上并不依赖于 com.google.code.findbugs:jsr305:1.3.9 JAR。因此,您应该可以自由地排除该依赖项并提供您自己使用的 javax.annotations JAR。或者,如果您更喜欢 com.google.code.findbugs:jsr305 JAR,则应从构建中排除 org.eclipse.jetty.orbit:javax.annotation 依赖项。您可以引用Maven documentation了解如何排除不需要的依赖项。

关于java - 为什么不同组织的javax.annotation不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33447686/

相关文章:

Java作为后端平台。好的选择?

java - 使用二进制数据对 java servlet 进行单元测试

java - 在文件中打印时分割值

java - 什么是脆弱的基类问题?

java - MessageResources 奇怪的行为

java - 为什么调用函数比不调用函数更快?

JQuery Mobile 加载 Wicket BookmarkablePageLink 时出错

java - 在哪里可以找到有关 Jetty API 的优质文档?

java - 如何使用java集合将数据存储在字符串数组中

java - 表示两个或多个因素之间的直接或反向关系的最佳 Guava (Google) 集合 API 是什么?