tags:

views:

283

answers:

4

Hi All,

I'd like to create like a "fat" jar with ant where I have, not only the usual classes, manifest files, etc, but also my 'libs' folder too.

I tried with:

<jar destfile="myjar.jar" update="yes" basedir="${libs.dir}"/>

but this adds the files in 'libs' the root of the jar file where I'd like to have the libs folder itself in the jar (with everything it contains of course)

Can I maybe create the lib folder myself in the jar and add the files to that specific location in the jar then ?

Cheers David

A: 

Use this ant extension: http://one-jar.sourceforge.net/

There is also Eclipse plugin: FatJar

nanda
I'm trying to do this with ant, and not with Eclipse...
DavidM
The one I pointed first works with ant
nanda
A: 

You have to do something like the following. Specifically, the zipfileset command. You basically are saying you want to build the ${build.name}.jar (you could hard code a path to be "myjar.jar" or something along those lines) and then add the various files to the JAR.

Hope this helps!

<jar destfile="${dist}/${build.name}.jar">

    <!-- Generate the MANIFEST.MF file. -->
    <manifest>
        <attribute name="Built-By" value="${user.name}" />
        <attribute name="Release-Version" value="${version}" />
        <attribute name="Main-Class" value="my.lib.Main" />
            <attribute name="SplashScreen-Image" value="TitleScreen.png" />
        <attribute name="Class-Path" value="${classpath}" />
    </manifest>

    <zipfileset dir="${build.dir}" />
    <zipfileset dir="${resources}" />

    <fileset file="${resources}/icons/misc_icons/TitleScreen.png" />
</jar>
JasCav
but with the fileset command, I have to specify each and everyone of files in the libs folder ?
DavidM
Not fileset...ZIPfileset. Check out the description here - it does exactly what you're looking for: http://ant.apache.org/manual/CoreTypes/zipfileset.html. It says, "When the dir attribute is used, the zipfileset is populated with filesystem files found under dir." (This is similar to my example.)
JasCav
+1  A: 

If you specify to use the directory as the root for your file set then you can just match for the directory and it will preserve the structure.

<jar destfile="myjar.jar" >
  <fileset dir=".">
    <include name="**/${libs.dir}/**"/>
  </fileset>
</jar>
mangoDrunk