【问题标题】:Zip file empty using maven assembly plugin in pom在 pom 中使用 maven 程序集插件清空 Zip 文件
【发布时间】:2017-02-02 11:36:28
【问题描述】:

我的 pom.xml 但我写了类似的东西

.......
..........
    <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.5.3</version>
            <configuration>
                <finalName>${project.artifactId}</finalName>
                <descriptor>assembly.xml</descriptor>
            </configuration>
            <executions>
                <execution>
                    <id>create-archive</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
    </plugin>
..........
.......

我的 assembly.xml 是

<assembly
    xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
    <id>${project.version}</id>
    <includeBaseDirectory>false</includeBaseDirectory>
    <formats>
        <format>zip</format>
    </formats>
    <fileSets>
        <fileSet>
            <directory>${project.basedir}/${create.stage.directory}</directory>
             <includes>
                <include>*.*</include>
            </includes>
            <outputDirectory>${project.basedir}/${create.release.directory}</outputDirectory>
        </fileSet>
    </fileSets>
</assembly>

这会在目标中创建一个 EMPTY foldername.zip!!不在我提供的输出文件夹位置中。它始终是目标吗?我不能覆盖吗?? 但是在给定的目录路径中,我有 3 个文件夹(其中有一些文件)和 readme.txt。我只是尝试在包含标签中提供 *.txt,但我得到了空的 zip 文件夹。我一开始猜我的目录路径和输出目录路径有可能是错的。我直接硬编码还是没有运气。

请帮忙(这个问题不是重复的而是类似的,我已经尝试了几乎所有与此相关的stackoverflow问题。他们没有解决任何问题)

【问题讨论】:

  • 您想实现什么? ${create.stage.directory} 包含什么?您要创建项目的源代码包吗?

标签: maven maven-assembly-plugin


【解决方案1】:

详情见http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html#class_fileSet

您的描述符现在配置如下:

  • 创建一个名为${project.artifactId}的压缩包
  • 从目录${project.basedir}/${create.stage.directory} 将所有带有扩展名的文件(不是目录,因为它说*.*,而不是**/*.* 之类的东西放在${project.basedir}/${create.release.directory} 文件夹里面 zip。

尤其是最后一部分很奇怪。这些文件应该在 zip 中的什么位置结束?它应该是一个相对路径以使其可预测。

不喜欢在目标中创建 zip 文件?在插件配置中设置outputDirectory,而不是在程序集描述符中。

【讨论】:

  • 您好,感谢您的帮助。在您的帮助下,我实际上已经解决了空 zip 问题。 1)但是 outputDIrectory 问题仍然存在。它总是在目标目录中,因为它的默认值是 ${project.build.directory} 。正如你所看到的,我给出了不同的值但仍然无法覆盖。 2)另一个问题是我想压缩 a/b/c 中的内容,但在压缩 c 内容并打开 zip 文件夹后,我看到了 a/b/x 结构,但我只想要 c 中的内容。 :( :'(
  • 对不起,上面的第1点也得到了解决。我输入错误。但是我如何只得到c而不是a\b\c结构
  • 把文件集的directory改成${project.basedir}/${create.stage.directory}/a/b
  • 嗨,谢谢。我在使用 ${project.basedir}/${create.stage.directory}/a/b/c 创建的输出 zip 中有相同的 .so,但我想要里面的内容C。 ${project.basedir}/${create.stage.directory} 本身就是 project/a/b/c 我需要将 c 中的内容压缩到我提供的文件名中
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-21
  • 1970-01-01
  • 1970-01-01
  • 2016-11-06
  • 2010-11-07
相关资源
最近更新 更多