从 jar 中删除文件的 ant 任务 [英] ant task to remove files from a jar

查看:34
本文介绍了从 jar 中删除文件的 ant 任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何编写一个从之前编译的 JAR 中删除文件的 ant 任务?

How to write an ant task that removes files from a previously compiled JAR?

假设我的 JAR 中的文件是:

Let's say the files in my JAR are:

aaa/bbb/ccc/Class1
aaa/bbb/ccc/Class2
aaa/bbb/def/Class3
aaa/bbb/def/Class4

... 我想要一个没有 aaa.bbb.def 包的这个 JAR 文件的版本,我需要使用 ant 把它去掉,这样我最终会得到一个 JAR包含:

... and I want a version of this JAR file without the aaa.bbb.def package, and I need to strip it out using ant, such that I end up with a JAR that contains:

aaa/bbb/ccc/Class1
aaa/bbb/ccc/Class2

谢谢!

推荐答案

您是否尝试过使用 zipfileset 任务?

Have you tried using the zipfileset task?

<jar destfile="stripped.jar">
    <zipfileset src="full.jar" excludes="files/to/exclude/**/*.file"/>
</jar>

<小时>

例如:

<property name="library.dir" value="dist"/>
<property name="library.file" value="YourJavaArchive.jar"/>
<property name="library.path" value="${library.dir}/${library.file}" />
<property name="library.path.new" value="${library.dir}/new-${library.file}"/>

<target name="purge-superfluous">
    <echo>Removing superfluous files from Java archive.</echo>

    <jar destfile="${library.path.new}">
        <zipfileset src="${library.path}" excludes="**/ComicSans.ttf"/>
    </jar>

    <delete file="${library.path}" />
    <move file="${library.path.new}" tofile="${library.path}" />
</target>

这篇关于从 jar 中删除文件的 ant 任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆