【问题标题】:How to zip only specific directories using maven assembly plugin如何使用 Maven 程序集插件仅压缩特定目录
【发布时间】:2015-09-16 13:05:47
【问题描述】:

我在构建项目时使用 maven-assembly-plugin 创建项目的 zip 文件。这是成功的。现在我想要的是仅压缩项目中的特定目录。

这是我之前使用的 pom 中插件的代码。

 <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <id>make shared resources</id>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <phase>package</phase>
                        <configuration>
                            <descriptors>
                                <descriptor>resource.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

而resource.xml文件如下。

<assembly>
    <id>resources</id>
    <formats>
        <format>zip</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <fileSets>
        <fileSet>
            <!-- Since it bundles all the units -->
            <directory></directory>
            <outputDirectory>/project</outputDirectory>
            <excludes>
                <exclude>pom.xml</exclude>
                <exclude>*.iml</exclude>
                <exclude>*.jar</exclude>
                <exclude>**/src/**</exclude>
                <exclude>**/target/**</exclude>
                <exclude>resource.xml</exclude>
            </excludes>
        </fileSet>
    </fileSets>
</assembly>

我只想压缩 maven 构建中项目的一些目录。

作为一个例子,我在项目中有以下文件夹结构。

project

   |_directories

         |_dir1
             |_ ....
         |_dir2
             |_ ....
         |_dir3
            |_ ....
         |_pom.xml

我想要的是制作只包含目录文件夹的 zip 文件。提取我的 zip 文件时,它应该只包含其中的四个目录。

我怎样才能做到这一点? maven-assembly-plugin 是否足以做到这一点,还是我应该创建一个 mojo?

【问题讨论】:

标签: maven maven-assembly-plugin


【解决方案1】:

您滥用了directoryoutputDirectory

directory 是项目中要压缩文件的路径(因此在您的情况下应该是 directories),outputDirectory 是生成 zip 文件中的文件夹,文件集所在的位置(因为你不想要顶层目录,应该是/):

<assembly>
    <id>resources</id>
    <formats>
        <format>zip</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <fileSets>
        <fileSet>
            <!-- Take everything inside the directories folder -->
            <directory>directories</directory>
            <!-- And place it inside the root of the zip file -->
            <outputDirectory>/</outputDirectory>
        </fileSet>
    </fileSets>
</assembly>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-29
    • 1970-01-01
    • 1970-01-01
    • 2014-07-27
    • 2013-10-27
    • 2011-01-29
    • 2015-03-29
    相关资源
    最近更新 更多