Maven:过滤清单的类路径条目

Maven: Filter classpath entries for manifest

我已经通过official documentation.

中描述的方法将类路径上的jar名称添加到清单文件中

即通过添加

<manifest>
    <addClasspath>true</addClasspath>
</manifest>

到 ejb 插件。现在我不想要所有这样的文件,但想排除其中的一些(因为它们直接由 webSphere 提供,不应列出)。

问题:这里有什么可以应用的排除机制吗?

目标容器提供的 Maven 依赖项应列为 scope provided。根据 official documentation

This is much like compile, 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.

因此,您应该将相关依赖项设置为提供的范围:

<dependency>
    <groupId>...</groupId>
    <artifactId>..</artifactId>
    <version>...</version>
    <scope>provided</scope>
</dependency>

Maven 会用它来编译、测试,但不会用来打包。并且它也将被排除在清单类路径之外。

您可以查看 this SO question about difference between provided and compile scope (the default one, no need to specify it at each dependency declaraction) while this SO question 是否有完全相反的问题。