Untar / Unzip *.tar.xz with ANT

我只是一个虾纸丫 提交于 2021-01-27 07:21:09

问题


I want to extract a tarball-file with *.tar.xz with ant.

But I can only find, bunzip2, gunzip, unzip and untar as goals in ant and none of it seems to work.

So how can I expand a tarball-file with *.tar.xz with ant?


回答1:


The XZ format is not supported by the default Ant distribution, you'll need the Apache Compress Antlib.

Download the full Antlib with all the dependencies from here (add the three jars ant-compress,common-compress,xz in the lib directory of your ant), and use this task:

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

You have to use this two-steps process because even with the additional ant library, the "xz" value is still not supported by the compression attribute of the untar task, the task you'll normally use to extract compressed tars.




回答2:


In case somebody else like myself wants to do the same with maven managing 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>


来源:https://stackoverflow.com/questions/31603742/untar-unzip-tar-xz-with-ant

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