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?
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With