使用 Maven 创建 tar.gz 存档 [英] Creating a tar.gz archive with Maven
问题描述
我有一个 Maven 项目,在 src/main 目录下有一个名为 output 的子目录.这个文件夹需要打包成tar.gz.使用程序集插件时如下:
来自 pom.xml:
<finalName>front</finalName><插件><插件><artifactId>maven-assembly-plugin</artifactId><version>2.2-beta-5</version><配置><描述符><descriptor>src/main/assembly/assembly.xml</descriptor></描述符></配置></插件></插件></build>
程序集.xml:
<程序集><id>捆绑包</id><格式><format>tar.gz</format></格式><文件集><文件集><目录>src/main/output</directory></fileSet></fileSets></组装>
我的问题是,我尝试的结果是运行 tar 实用程序本身,这意味着在提取以获取 output 目录及其所有内容时.我得到的是包含所有项目路径的输出文件夹 - name/src/main/output.
您需要将程序集描述符配置为不包含基目录并为 fileSet<配置输出目录/代码>:
<程序集><id>捆绑包</id><格式><format>tar.gz</format></格式><includeBaseDirectory>false</includeBaseDirectory><文件集><文件集><目录>src/main/output</directory><outputDirectory>output</outputDirectory></fileSet></fileSets></组装>
使用上面的程序集描述符,我得到以下结果(在重现结构的项目上运行时):
<前>$ mvn 清洁装配:装配...$ cd 目标$ tar zxvf Q3330855-1.0-SNAPSHOT-bundle.tar.gz输出/输出/你好.txt另见
- 程序集描述符格式参考
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:
From the 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>
the assembly.xml:
<assembly>
<id>bundle</id>
<formats>
<format>tar.gz</format>
</formats>
<fileSets>
<fileSet>
<directory>src/main/output</directory>
</fileSet>
</fileSets>
</assembly>
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.
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
See also
- The Assembly Descriptor Format reference
这篇关于使用 Maven 创建 tar.gz 存档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!