Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ant task to remove files from a jar

How to write an ant task that removes files from a previously compiled 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 

... 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 

Thanks!

like image 846
bguiz Avatar asked Mar 26 '10 05:03

bguiz


People also ask

How do I remove a folder from a jar file?

Here's the process: Scan forward in the file until you find the first file you want to delete. Scan forward in the file until you find the first file you don't want to delete or you hit the central directory. Scan forward in the file until you find the first file you want to delete or you hit the central directory.

Which one is true code for delete the directory in ant?

This task is used to delete a single file, directory or subdirectories. We can also delete set of files by specifying set of files. It does not remove empty directory by default, we need to use includeEmptyDirs attribute to remove that directory.

What is Ant task in Java?

Ant tasks are the units of your Ant build script that actually execute the build operations for your project. Ant tasks are usually embedded inside Ant targets. Thus, when you tell Ant to run a specific target it runs all Ant tasks nested inside that target.


1 Answers

Have you tried using the zipfileset task?

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

For example:

<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> 
like image 56
mipadi Avatar answered Oct 04 '22 04:10

mipadi