gpt4 book ai didi

maven - 如何使用Maven程序集插件仅压缩特定目录

转载 作者:行者123 更新时间:2023-12-04 16:59:25 29 4
gpt4 key购买 nike

构建项目时,我正在使用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?

最佳答案

您误用了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>

关于maven - 如何使用Maven程序集插件仅压缩特定目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32609461/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com