Java Jar Ant include folder

15,031

Solution 1

Change the last line to

<fileset dir="." includes="data/**" />

No need to copy files around.

An alternative way (which is useful if you want to have the directory in the archive to have a different name) would be

<zipfileset dir="data" includes="." prefix="folder-name-in-jar"/>

Solution 2

First, you create the file structure you need and copy to it all the files required. Then you run jar command on the resulting root directory.

In order to copy files you can use the ANT copy task For example:

<copy todir="../dest/dir">
<fileset dir="." includes="data/**/*.java">
</fileset>

More on how to pack jar (basics) here

Share:
15,031
jhbruhn
Author by

jhbruhn

Just doing things.

Updated on June 18, 2022

Comments

  • jhbruhn
    jhbruhn almost 2 years

    My Question is: How am i able to put files in a subdirectory into my jar via ant? Right now my Code is:

    <jar destfile="${dist.dir}\wo42.jar" basedir="bin">
    <manifest>
        <attribute name="Main-Class" value="org.alternativedev.wo42.App" />
        <attribute name="Class-Path" value="lib" />
    </manifest>
    <zipgroupfileset dir="lib/." excludes="natives/*" />
    <fileset dir="data/." includes="." />
    

    It creates a structure like

    ROOT-Jar
    -org
    --bla
    -filefromdata1
    -filefromdata2
    

    But it should be

    ROOT-Jar
    -org
    --bla
    -data
    --filefromdata1
    --filefromdata2
    

    Do You know what I mean?

    Greetings, BigTeddy

  • jhbruhn
    jhbruhn about 12 years
    Thanks very much, that was the solution :)