Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Untar / Unzip *.tar.xz with ANT

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?

like image 669
Sebastian Röher Avatar asked Mar 15 '23 07:03

Sebastian Röher


2 Answers

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.

like image 94
uraimo Avatar answered Apr 12 '23 13:04

uraimo


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>
like image 21
Greg Domjan Avatar answered Apr 12 '23 15:04

Greg Domjan