【发布时间】:2015-07-24 06:34:56
【问题描述】:
我想用 ant 解压带有 *.tar.xz 的 tarball 文件。
但我只能在 ant 中找到 bunzip2、gunzip、unzip 和 untar 作为目标,但似乎都不起作用。
那么我如何用 ant 扩展带有 *.tar.xz 的 tarball 文件?
【问题讨论】:
我想用 ant 解压带有 *.tar.xz 的 tarball 文件。
但我只能在 ant 中找到 bunzip2、gunzip、unzip 和 untar 作为目标,但似乎都不起作用。
那么我如何用 ant 扩展带有 *.tar.xz 的 tarball 文件?
【问题讨论】:
默认的 Ant 发行版不支持 XZ 格式,您需要 Apache Compress Antlib。
从 here 下载完整的 Antlib 以及所有依赖项(在你的 ant 的 lib 目录中添加三个 jars ant-compress、common-compress、xz),然后使用这个任务:
<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一起使用,以避免临时文件如果像我这样的其他人也想用 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>
【讨论】: