【问题标题】:Maven assembly plugin not creating tar files with directory entries?Maven 程序集插件没有创建带有目录条目的 tar 文件?
【发布时间】:2012-04-10 22:07:21
【问题描述】:

我正在开发我的第一个 Maven 项目,该项目最终会将 Java 应用程序打包到 Debian 包中(使用 jdeb 插件)。我正在尝试使用程序集插件来构建一个 tar 文件,但看起来生成的文件并不总是包含目录条目,这将导致 dpkg install 失败。

有人见过吗?

具体来说,生成的 tar 文件不包含以下目录条目:

  • 指定<includes> 的文件集(离开<includes> 将导致tar 文件中的目录条目)
  • 一个依赖集

这是一个不使用<includes>的程序集文件

<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>simple</id>
<formats>
    <format>tar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>

<moduleSets>
</moduleSets>
<fileSets>
    <fileSet>
        <directory>src/main/config</directory>
        <outputDirectory>/etc/${project.artifactId}</outputDirectory>

    </fileSet>
</fileSets>

<dependencySets>

    <dependencySet>
        <outputDirectory>/usr/lib/${project.artifactId}/lib</outputDirectory>
        <scope>runtime</scope>
        <useProjectArtifact>true</useProjectArtifact>
    </dependencySet>

</dependencySets>
<repositories>
</repositories>
<componentDescriptors />
</assembly>

以下是 tar 文件的内容:

 tar tvf assembly-test-0.0.1-SNAPSHOT-simple.tar
drwxr-xr-x 0/0               0 2012-04-10 12:54 etc/assembly-test/
-rw-r--r-- 0/0               0 2012-04-10 12:52 etc/assembly-test/file1.xml
-rw-r--r-- 0/0               0 2012-04-10 12:52 etc/assembly-test/file2.xml
-rw-r--r-- 0/0            2131 2012-04-10 13:26 usr/lib/assembly-test/lib/assembly-test-0.0.1-SNAPSHOT.jar

现在,如果我使用带有一些包含模式的程序集:

<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>include-match</id>
<formats>
    <format>tar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>

<moduleSets>
</moduleSets>
<fileSets>
    <fileSet>
        <directory>src/main/config</directory>
        <outputDirectory>/etc/${project.artifactId}</outputDirectory>
        <includes>
            <include>*.xml</include>
        </includes>
    </fileSet>
</fileSets>

<dependencySets>

    <dependencySet>
        <outputDirectory>/usr/lib/${project.artifactId}/lib</outputDirectory>
        <scope>runtime</scope>
        <useProjectArtifact>true</useProjectArtifact>
    </dependencySet>

</dependencySets>
<repositories>
</repositories>
<componentDescriptors />
</assembly>

tar 文件的内容丢失目录项:

tar tvf assembly-test-0.0.1-SNAPSHOT-include-match.tar
-rw-r--r-- 0/0               0 2012-04-10 12:52 etc/assembly-test/file1.xml
-rw-r--r-- 0/0               0 2012-04-10 12:52 etc/assembly-test/file2.xml
-rw-r--r-- 0/0            2131 2012-04-10 13:26 usr/lib/assembly-test/lib/assembly-test-0.0.1-SNAPSHOT.jar

这似乎是程序集插件中的一个错误,尽管我仍在试验它。我当然可以解决它(在包中使用 preinst 脚本,也许构建一个目录结构供 jdeb 构建),但我希望尽可能多地保留在描述符文件中。

【问题讨论】:

  • 可能是因为第一个文件集(不带“includes”)正在复制整个目录,而第二个版本(带“includes”)仅复制匹配的模式(“xml”),并且目录与该模式不匹配?
  • 每次我尝试使用包含的通配符模式时,目录条目都不会添加到 tar - 任何包含似乎都会阻止它。但是只有一个排除模式,才会创建条目 。它似乎不一致,可能只是目录过滤方式的副产品。

标签: java maven tar


【解决方案1】:

我想我可以用一种可以强制在 tar 文件中创建目录条目的方法来回答这个问题(我实际上在其他地方找到了这个,但不记得在哪里) - 添加一个 fileSet 同时排除所有内容,例如:

        <!-- force entry for /usr/lib/${project.artifactId} -->
        <fileSet>
            <directory></directory>
            <outputDirectory>/usr/lib/${project.artifactId}</outputDirectory>
            <excludes>
                <exclude>*/**</exclude>
            </excludes>
        </fileSet>

不优雅,如果你有很多目录会变得冗长,但它有效。但是,对于我创建 debian 包的具体情况,我最终使用 Assembly 插件来构建“目录”格式的程序集,然后让 jdeb 插件使用目录结构(并设置文件模式),结果有点整体更简单。

【讨论】:

    【解决方案2】:

    有一个简单的方法可以解决这个问题,只需包含您想要的目录或“**/”,如果您想要所有这些,例如:

    <include>mydir/**/</include>
    

    注意尾随的 / 因为这是拉入目录的内容。我认为当前的行为可能是故意的,因为 include 似乎准确地拉入了您所包含的内容,而不是其他任何内容。顺便说一句,虽然生成的 tarball 不满足 npm,所以 maven 的支持似乎仍然有点可疑。

    【讨论】:

      猜你喜欢
      • 2010-12-12
      • 2013-10-27
      • 2015-08-03
      • 1970-01-01
      • 2010-09-24
      • 2018-02-01
      • 2019-05-22
      • 1970-01-01
      • 2017-08-24
      相关资源
      最近更新 更多