Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / March 2006

Tip: Looking for answers? Try searching our database.

ant, jar with selected directories

Thread view: 
DaveO. - 29 Mar 2006 20:55 GMT
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. - 30 Mar 2006 20:00 GMT
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 - 30 Mar 2006 20:51 GMT
>    <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
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.