Maven:简单的classpathLayoutType生成类似于repository classpathLayoutType的类路径

时间:2018-01-17 11:21:33

标签: java maven maven-jar-plugin

我有一个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?

我已经使用自定义layoutType实现了我需要的内容,如下所示:

<classpathLayoutType>custom</classpathLayoutType>
<customClasspathLayout>lib/$${artifact.artifactId}-$${artifact.version}$${dashClassifier?}.$${artifact.extension}</customClasspathLayout>

我唯一的问题是为什么简单的layoutType不起作用?

1 个答案:

答案 0 :(得分:1)

您正在使用哪个MavenArchiver插件? 3.0.2具有a bug in ManifestConfiguration.class

 public String getClasspathLayoutType()
 {
    return "simple".equals(this.classpathLayoutType) ? "repository" : this.classpathLayoutType;
  }

如您所见,ClasspathLayoutType的方法返回了错误的类型。 在MavenArchiver版本3.1.1中,该错误已修复。 布局类型的可能返回值是:

  public static final String CLASSPATH_LAYOUT_TYPE_SIMPLE = "simple";
  public static final String CLASSPATH_LAYOUT_TYPE_REPOSITORY = "repository";
  public static final String CLASSPATH_LAYOUT_TYPE_CUSTOM = "custom";

只需尝试更高的固定版本。

相关问题