Ant任务从一个罐子中删除文件 [英] ant task to remove files from a jar

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

问题描述

如何写一个Ant任务,从previously编译JAR文件中删除?

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>

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

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