![](/img/trans.png)
[英]How can we zip two separate directories in seperate zip files, using assembly plugin?
[英]How to zip only specific directories using maven assembly plugin
我在构建项目时使用 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?
您误用了directory
和outputDirectory
。
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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.