【发布时间】:2020-09-22 05:02:26
【问题描述】:
我正在使用maven 构建一个可执行文件JAR,并且我想将所有依赖项添加到我的MANIFEST.MF 的Class-Path 中减去少数几个。到目前为止,我为此使用maven-jar-plugin:
<!-- Add dependent JARs to the classpath -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>libraries</classpathPrefix>
<mainClass>MyMainClass</mainClass>
</manifest>
<manifestEntries>
<Built-By>Me</Built-By>
</manifestEntries>
</archive>
</configuration>
</plugin>
这适用于添加所有依赖项。但是,我还想排除某些依赖项被添加到Class-Path。根据the documentation,您可以使用exclude标签如下:
<configuration>
<!-- ... -->
<excludes>
<exclude>**selenium*</exclude>
</excludes>
<!-- ... -->
</configuration>
我希望这会排除任何名称中包含 selenium 但它不起作用的依赖项。例如,我想从Class-Path 中排除libraries/selenium-json-4.0.0-alpha-6.jar。即使我指定了确切的名称,它也不会排除任何东西。我还想提供groupId 用于排除类似于maven-dependency-plugin 的excludeGroupIds 标签的工作方式。
如何使用maven 完成所需的Class-Path 管理?
我还使用maven-shade-plugin 来构建可执行文件(胖)JAR,但它的清单操作工具似乎鲜为人知/记录在案。使用maven-shade-plugin 通过this 答案设置Class-Path 有效,但是如何使用排除项填充我的依赖项而不是对所有内容进行硬编码?
【问题讨论】:
-
您已经找到解决方案了吗?如果有,请更新。
标签: java maven jar executable-jar