ant任务从jar中删除文件

bgu*_*uiz 32 java ant packages jar

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

假设我的JAR中的文件是:

aaa/bbb/ccc/Class1
aaa/bbb/ccc/Class2
aaa/bbb/def/Class3
aaa/bbb/def/Class4
Run Code Online (Sandbox Code Playgroud)

...我想要一个没有aaa.bbb.def包的JAR文件的版本,我需要使用ant将其删除,这样我最终会得到一个包含以下内容的JAR:

aaa/bbb/ccc/Class1
aaa/bbb/ccc/Class2
Run Code Online (Sandbox Code Playgroud)

谢谢!

mip*_*adi 58

你尝试过使用这个zipfileset任务吗?

<jar destfile="stripped.jar">
    <zipfileset src="full.jar" excludes="files/to/exclude/**/*.file"/>
</jar>
Run Code Online (Sandbox Code Playgroud)

例如:

<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>
Run Code Online (Sandbox Code Playgroud)

  • 还可以使用“zip”而不是“jar”来避免更改 MANIFEST.MF (2认同)

Dav*_*vid 5

你必须解开并重新开始.

<unzip src="myjar.jar" dest="/classes/">
<jar destfile="newjar.jar"
    basedir="/classes/"
    includes="**/*"
    excludes="**/def/*"
/>    
Run Code Online (Sandbox Code Playgroud)