为什么 Jersey 2.22 在 Jersey 捆绑包中包含 "javax.servlet-api-3.0.1"?

Why does Jersey 2.22 have "javax.servlet-api-3.0.1" included in the Jersey bundle?

Servlet 规范 3.0:

Web Application Class Loader The class loader that a container uses to load a servlet in a WAR must allow the developer to load any resources contained in library JARs within the WAR following normal Java SE semantics using getResource. As described in the Java EE license agreement, servlet containers that are not part of a Java EE product should not allow the application to override Java SE platform classes, such as those in the java.* and javax.* namespaces, that Java SE does not allow to be modified. The container should not allow applications to override or access the container’s implementation classes

鉴于此,我不明白为什么 Jersey 2.22 在 Jersey 2.22 捆绑包中包含 javax.servlet-api-3.0.1 jar。为什么它在那里有任何合理的解释吗?默认情况下,我认为 Glassfish、Tomcat 等容器在 lib 目录中有自己的 servlet-api.jar。

如果检查此 link,您会发现它是 提供的依赖项 ,这意味着编译应用程序 需要依赖项,但在使用库时应该是默认提供的。

Maven documentation 解释了 provided 依赖范围的工作原理:

This is much like compile [dependency scope], but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.

Jersey 2.22.x bundle 包含 JAX-RS 2.0 API jar、所有核心 Jersey 模块 jar 以及所有必需的第 3 方依赖项。