【发布时间】:2020-05-09 21:01:29
【问题描述】:
我正在使用 Maven 和 Maven-jar-plugin 开发 java 项目 我使用 maven jar 插件在 MANIFEST.MF 中为我的 jar 文件生成了依赖项的类路径。 这是我的插件用法:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
<manifestEntries>
<Build-Time>${maven.build.timestamp}</Build-Time>
</manifestEntries>
<manifestSections>
<manifestSection>
<name>${project.name}</name>
<manifestEntries>
<git-branch>${git.branch}</git-branch>
<git-build-host>${git.build.host}</git-build-host>
<git-build-time>${git.build.time}</git-build-time>
<git-build-user-email>git.build.user.email</git-build-user-email>
<git-build-user-name>git.build.user.name</git-build-user-name>
<git-build-version>${git.build.version}</git-build-version>
</manifestEntries>
</manifestSection>
</manifestSections>
</archive>
</configuration>
</plugin
而生成的classpath是这样的:
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Build-Time: 2020-01-23T13:34:14Z
Class-Path: org/apache/logging/log4j/log4j-api-2.6.2.jar
org/apache/logging/log4j/log4j-core-2.6.2.jar
org/apache/commons/commons-configuration2-2.2.jar org/apache/commons/commons-lang3-3.6.jar
commons-loggin g/commons-logging-1.2.jar
commons-beanutils/commons-beanutils-1.9.3.jar
commons-collections/commons-collections-3.2.2.jar
Created-By: Apache Maven 3.6.2
Build-Jdk: 1.8.0_181
Name: service_utils
git-commit-id-abbrev: d78e66c
但我确实需要使用相对路径而不是通过lib 或WEB-INF 的路径来生成我的类路径。 我希望有这样的东西:
Manifest-Version: 1.0
Class-Path:
../../../org/hibernate/hibernate-core/5.1.0.Final/hibernate-core-5.1.0.Final.jar ../artifacts/org/hibernate/hibernate-core/5.1.0.Final/hibernate-core-5.1.0.Final.jar ../../../org/hibernate/common/hibernate-commons-annotations/5.0.1.Final/hibernate-commons-annotations-.0.1.Final.jar
../artifacts/org/hibernate/common/hibernat e-commons-annotations/5.0.1.Final/hibernate-commons-annotations-5.0.1 .Final.jar
../../org/jboss/logging/jboss-logging/3.3.0.Final/jboss-logging-3.3.0.Final.jar
../artifacts/org/jboss/logging/jboss-logging/3.3.0.Final/jboss-logging-3.3.0.Final.jar
../../../com/mchange/c3p0/ 0.9.2.1/c3p0-0.9.2.1.jar
我已经搜索和研究了 StackOverflow 的许多关于在 jar 文件中使用它们的相对路径类路径的清单文件的问题,我已经看到了 gradle 的选项,但我正在寻找 maven 解决方案,如果我可以使用 maven jar 执行此操作会更好插件。
【问题讨论】:
标签: maven jar maven-plugin manifest.mf maven-jar-plugin