【发布时间】:2018-01-17 11:21:33
【问题描述】:
我有一个 Maven 项目,它执行以下操作:生成 jar 并将其复制到 target/dist 目录中。将所有依赖项 jar 复制到 target/dist/lib 目录中。 dist 文件夹将被分发。生成的 jar 执行时,需要在类路径中执行依赖 jar。当我在 pom.xml 中添加以下代码时,
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
在生成的jar文件中,类路径生成如下:
Class-Path: lib/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar lib/com/google/code/gson/gson/2.8.2/gson-2.8.2.jar
显然,这不会起作用,因为类路径不同。我希望类路径如下:
Class-Path: lib/commons-logging-1.1.1.jar lib/gson-2.8.2.jar
我推荐了this page。根据文档,默认情况下 classpathLayoutType 很简单,这就是我所需要的。但是在存储库布局类型中生成的类路径。我什至尝试明确添加以下标签,但没有成功。
<classpathLayoutType>simple</classpathLayoutType>
为什么简单的layoutType会像repository layoutType那样生成classpath?
我已经使用自定义 layoutType 实现了我需要的功能,如下所示:
<classpathLayoutType>custom</classpathLayoutType>
<customClasspathLayout>lib/$${artifact.artifactId}-$${artifact.version}$${dashClassifier?}.$${artifact.extension}</customClasspathLayout>
我唯一的问题是为什么简单的 layoutType 不起作用?
【问题讨论】:
标签: java maven maven-jar-plugin