ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Bodewig <>
Subject Re: Using ant/jarjar to make nested jars flattened
Date Fri, 12 Feb 2010 09:40:37 GMT
On 2010-02-11, Josh Stratton <> wrote:

> I'm using jarjar as I'm told it is useful for bundling jar
> dependencies into a single distributable jar file. I have a problem
> though in how jars are unzipped. This is probably a simple ANT
> question, but I haven't had much luck with finding help on it in java
> related forums, so I thought I'd go directly to the source (unless
> that is the jarjar site...).

I'm afraid the jarjar support might be the better place.

> <target name="package">
>       <taskdef name="jarjar"
> classname="com.tonicsystems.jarjar.JarJarTask"
> classpath="./lib/jarjar.jar"/>
>       <jarjar jarfile="dist/inkspot.jar">
>           <fileset dir="./build/classes"/>
>           <!-- <zipfileset src="./lib/"/>
> --> // line A
>           <zipfileset dir="./lib"/> // line B
>           <zipfileset dir="${jogl.dir}"/>
>       </jarjar>
>   </target>

> I'm trying to include the scala library jar into my code. It has six
> jars inside of it (scala-swing.jar, scala-library.jar, etc.).

<zipfileset> won't help here since it only does one level of
un-nesting and you'd need two (extract the main jar then extract the
nested jars).

If you are using Ant 1.8.0 and <jarjar> is an extension of <jar> that
supports arbitrary resource collections just like <jar> does (I think it
is, I'm not sure) then the new <archives> resource collection can help.
If you put

    <zipfileset src="./lib/"/>

as a nested element into your jarjar task it will first extract all
files from the big jar (the inner zipfileset) and then treat them as
zips and extract all files from them.


Oh no, on second thought it won't work, sorry.

Ant's built-in ZIP classes can only read from files, not from streams.
What you'd need would be the archives resource collection from the (not
yet released) Compress Antlib which sits on top of Apache Commons
Compress and does support readings ZIPs from streams.

Unless you are willing to build the library yourself (supposed to be
released soonish), the only workaround is to manually extract and use a zipgroupfileset on the dir
holding the extracted files - this should work with almost any version
of Ant:

<property name="extracted" location="${}/extracted"/>
<mkdir dir="${extracted}"/>
<unzip src="./lib/"
<jarjar ...>
  <zipgroupfileset dir="${extracted}"/>
<delete dir="${extracted}"/>


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message