使用 Maven 创建 tar.gz 存档

发布于 09-11 16:44 字数 1026 浏览 14 评论 0 原文

我有一个 Maven 项目,在 src/main 目录下有一个名为 output 的子目录。该文件夹需要打包成tar.gz。使用程序集插件时如下:

来自 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>

程序集.xml:

<assembly>
    <id>bundle</id> 
    <formats>
        <format>tar.gz</format>
    </formats>
    <fileSets>
        <fileSet>
            <directory>src/main/output</directory>
        </fileSet>
</fileSets>
</assembly>

我的问题是我正在尝试结果将与运行 tar 实用程序本身一样,这意味着在提取时获取输出目录及其所有内容。我得到的是包含所有项目路径的输出文件夹 - name/src/main/output。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

电影里的梦 2024-09-18 16:44:23

您需要将程序集描述符配置为包含基目录,并为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>

使用上面的程序集描述符,我得到以下结果(当在重现结构的项目上运行):

$ mvn clean assembly:assembly
...
$ cd target
$ tar zxvf Q3330855-1.0-SNAPSHOT-bundle.tar.gz 
output/
output/hello.txt

另请参阅

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

月下伊人醉 2024-09-18 16:44:23

尝试在 ="">outputDirectory >文件集。这应该删除 src/main/output 目录。

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

您可能还需要设置 includeBaseDirectory 为假。这将删除名称目录。

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

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>
  <!-- ... -->
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文