使用Maven创建tar.gz存档 [英] Creating a tar.gz archive with Maven
问题描述
我有一个Maven项目,在src/main目录下有一个名为output的子目录.该文件夹需要打包到tar.gz中.如下使用组装插件时:
I have a Maven project, where under src/main directory there is a sub dir called output. this folder needs to be packaged into tar.gz. when using the assembly plugin as follows:
通过pom.xml:
<build>
<finalName>front</finalName>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
<configuration>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</plugin>
</plugins>
</build>
assembly.xml:
the assembly.xml:
<assembly>
<id>bundle</id>
<formats>
<format>tar.gz</format>
</formats>
<fileSets>
<fileSet>
<directory>src/main/output</directory>
</fileSet>
</fileSets>
</assembly>
我的问题是我尝试的结果是运行tar实用程序本身,这意味着在提取以获取 output 目录及其所有内容时.我得到的是包含所有项目路径的输出文件夹-name/src/main/output.
My problem is that I am trying the outcome will be as running the tar utility itself, meaning when extracting to get output directory and all its content. what I get is the output folder wrapped with all the project path - name/src/main/output.
推荐答案
您需要将程序集描述符配置为不包括基本目录,并为fileSet
配置输出目录:
You need to configure the assembly descriptor to not include the base directory and to configure an output directory for the fileSet
:
<assembly>
<id>bundle</id>
<formats>
<format>tar.gz</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>src/main/output</directory>
<outputDirectory>output</outputDirectory>
</fileSet>
</fileSets>
</assembly>
使用上面的汇编描述符,我得到以下结果(在运行再现结构的项目中运行时):
With the above assembly descriptor, I get the following result (when running on a project reproducing the structure):
$ mvn clean assembly:assembly
...
$ cd target
$ tar zxvf Q3330855-1.0-SNAPSHOT-bundle.tar.gz
output/
output/hello.txt
另请参见
- 程序集描述符格式参考
- The Assembly Descriptor Format reference
See also
这篇关于使用Maven创建tar.gz存档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!