【问题标题】:Untar / Unzip *.tar.xz with ANT使用 ANT 解压 / 解压 *.tar.xz
【发布时间】:2015-07-24 06:34:56
【问题描述】:

我想用 ant 解压带有 *.tar.xz 的 tarball 文件。

但我只能在 ant 中找到 bunzip2、gunzip、unzip 和 untar 作为目标,但似乎都不起作用。

那么我如何用 ant 扩展带有 *.tar.xz 的 tarball 文件?

【问题讨论】:

    标签: ant tar unzip gunzip


    【解决方案1】:

    默认的 Ant 发行版不支持 XZ 格式,您需要 Apache Compress Antlib

    here 下载完整的 Antlib 以及所有依赖项(在你的 ant 的 lib 目录中添加三个 jars ant-compresscommon-compressxz),然后使用这个任务:

    <target name="unxz">
        <cmp:unxz src="foo.tar.xz" xmlns:cmp="antlib:org.apache.ant.compress"/>
        <untar src="foo.tar" dest="."/>
        <delete file="foo.tar"/>
    </target>
    

    您必须使用这个两步过程,因为即使使用附加的 ant 库,untar 任务的 compression 属性仍然不支持 "xz" 值,您通常使用的任务提取压缩的焦油。

    【讨论】:

    • 您可以将untar的“嵌套资源”支持与Compress Antlib的xzresource一起使用,以避免临时文件
    • @StefanBodewig 好多了!!
    【解决方案2】:

    如果像我这样的其他人也想用 maven 管理 ant 做同样的事情。

    <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.7</version>
        <dependencies>
    <!--    Optional:   May want to use more up to date commons compress, add this dependency
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-compress</artifactId>
                <version>1.10</version>
            </dependency> -->
            <dependency>
                <groupId>org.apache.ant</groupId>
                <artifactId>ant-compress</artifactId>
                <version>1.4</version>
            </dependency>
        </dependencies>
        <executions>
            <execution>
                <id>unpack</id>
                <phase>generate-sources</phase>
                <goals><goal>run</goal></goals>
                <configuration>
                    <target name="unpack">
                        <taskdef resource="org/apache/ant/compress/antlib.xml" classpathref="maven.plugin.classpath"/>
                        <unxz src="${xz.download.file}" dest="${tar.unpack.directory}" />
                        <untar src="${tar.unpack.file}" dest="${final.unpack.directory}"/>
                    </target>
                </configuration>
            </execution>
        </executions>
    </plugin>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-30
      • 2013-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多