Creating a tar.gz archive with Maven

半世苍凉 提交于 2019-12-21 07:30:46

问题


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.


回答1:


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



回答2:


Try setting outputDirectory in the fileSet. That should remove the src/main/output directories.

<fileSet>
  <directory>src/main/output</directory>
  <outputDirectory>.</outputDirectory>
</fileSet>

You may also need to set includeBaseDirectory to false. That would remove the name directory.

<assembly>
  <id>bundle</id> 
  <includeBaseDirectory>false</includeBaseDirectory>
  <!-- ... -->


来源:https://stackoverflow.com/questions/3330855/creating-a-tar-gz-archive-with-maven

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!