Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Jar Ant include folder

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

like image 906
jhbruhn Avatar asked Feb 19 '12 11:02

jhbruhn


2 Answers

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"/>
like image 76
Philipp Wendler Avatar answered Oct 23 '22 11:10

Philipp Wendler


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

like image 21
aviad Avatar answered Oct 23 '22 12:10

aviad