开发者

how to add a complete folder to a jar file by ant

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 ?


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>


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

There is also Eclipse plugin: FatJar


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>


http://www.vertigrated.com/blog/2009/11/how-to-bundle-command-line-programs-into-a-single-executable-jar-file/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜