For Programmers: Free Programming Magazines  


Home > Archive > Java Help > March 2006 > ant, jar with selected directories









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author ant, jar with selected directories
DaveO.

2006-03-29, 7:04 pm

Hello,

I'm tyring to use Ant to create a jar file with selected directories in
a potentially large tree.
For example:

<property name="top.dir" value="/javasrc"/>
<property name="util.dir" value="/javasrc/my/stuff/util"/>
<property name="Proj1.dir" value="/javasrc/other/stuff/Proj1"/>
<property name="jar.file" value="Proj1.jar"/>

I can do this:

<jar basedir="${top.dir}" destfile="${top.dir}/${jar.file}"
includes="**/*.class">

But of course I get all classfiles under /javasrc. I've been tinkering
with includes= and <fileset> to try and pick and choose the directories
to include, without success. Also, I often get just the class file name
referenced in the manifest, but what I need is

/javasrc/my/stuff/util/a.class

So far the only thing that's worked is includesfile, but then I have to
maintain the file. This seems like a pretty natural thing to do... Any
suggestions???

Thanks,
Dave

DaveO.

2006-03-30, 7:05 pm

Well, I solved it... The key was in this sentence in the Ant docs for
the jar task:

The extended fileset and groupfileset child elements from the zip task
are also available in the jar task.

Which enabled me to do this:

<property name="top.dir" value="/javasrc"/>
<property name="util.dir" value="my/stuff/util"/>
<property name="Proj1.dir" value="other/stuff/Proj1"/>
<property name="jar.file" value="Proj1.jar"/>

<target name="jar">
<jar destfile="${top.dir}/${jar.file}">
<zipfileset dir="${top.dir}/${jws.dir}" prefix="${util.dir}"
includes="*.class"/>
<zipfileset dir="${top.dir}/${jcw.dir}" prefix="${Proj1.dir}"
includes="*.class"/>
</jar>
</target>

The jar task specifies no contents, and each of the zipfileset elements
specifies a directory, and prepends the path when the files are stored.

cheers,
Dave

Roedy Green

2006-03-30, 7:05 pm

On 30 Mar 2006 11:00:42 -0800, "DaveO." <daveoverbeck@yahoo.com>
wrote, quoted or indirectly quoted someone who said :

> <jar destfile="${top.dir}/${jar.file}">
> <zipfileset dir="${top.dir}/${jws.dir}" prefix="${util.dir}"
>includes="*.class"/>
> <zipfileset dir="${top.dir}/${jcw.dir}" prefix="${Proj1.dir}"
>includes="*.class"/>
> </jar>


check out genjar. It makes sure you have not forgotten anything or
including stuff that does not need to be there.

See http://mindprod.com/jgloss/genjar.html
http://mindprod.com/jgloss/ant.html
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com