繁体   English   中英

如何在maven中创建特定目录的zip文件?

[英]How to create a zip file of a specific directory in maven?

在此处输入图像描述任何人都可以帮我解决这个问题。 使用 maven ,我需要创建一个目录的 zip 文件,该目录位于项目内部。

任何例子都会有所帮助。

maven 程序集插件可以创建任何你想要的 zip 文件。 文档非常好,您可以在此处查看示例。

它的要点是添加一个描述如何组装文件的 xml 文件,然后从 pom.xml 中引用它。 这是程序集描述符的示例(取自网站):

<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd">
  <id>distribution</id>
  <formats>
    <format>zip</format>
  </formats>
  <files>
    <file>
      <source>README.txt</source>
      <outputDirectory></outputDirectory>
      <filtered>true</filtered>
    </file>
    <file>
      <source>LICENSE.txt</source>
      <outputDirectory></outputDirectory>
    </file>
    <file>
      <source>NOTICE.txt</source>
      <outputDirectory></outputDirectory>
      <filtered>true</filtered>
    </file>
  </files>
</assembly>

然后在pom.xml中,您将像这样引用此文件(假设该文件在assembly目录下名为distribution.xml ):

<project>
  [...]
  <build>
    [...]
    <plugins>
      [...]
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>3.3.0</version>
        <configuration>
          <descriptors>
            <descriptor>src/assembly/distribution.xml</descriptor>
          </descriptors>
        </configuration>
      </plugin>
   [...]
</project>

还有更多选项可以帮助您过滤掉文件或包含/排除目录等。 全部在文档中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM