Assume I have a project with the following file in it:
/folder1/folder2/folder3/folder4/some_file
Now, assume I am jar-ing that file using <jar> ant task. However,
assume I want this file to be not in /folder1/folder2/folder3/folder4/
in the jar, but somewhere else, e.g.:
/folder10/some_file
i.e. just place it in some other folder in the jar.
Can this be done somehow (without actually moving the file)? One
option is to copy it before it's actually jar-ed, but this is
"hacky" (it is a solution, though) - any other (just of curiosity)? I
tried the mappers, but that didn't work (it says "jar doesn't support
the nested "mapper" element.")
Ian Shef - 14 Sep 2007 20:19 GMT
wimxa@yahoo.com wrote in news:1189796859.311184.272020
@k79g2000hse.googlegroups.com:
> Assume I have a project with the following file in it:
>
[quoted text clipped - 9 lines]
>
> Can this be done somehow (without actually moving the file)?
<snip>
A jar file is basically a zip file with a manifest file stored within it.
If you have a tool that manipulates zip files, you should be able to do
anything to a jar file that you can do to a zip file.
You might have to change the file extension to zip, and later back to jar.
Because of the way that data is stored in a zip file, what you are
requesting probably requires that:
1) The file be unzipped or unjarred (a tool might do this to a temporary
location).
2) The directory be renamed.
3) The files get zipped or jarred again, this time starting from the
renamed point of the directory tree instead of from the top.
Because the java package java.util.jar provides support for jar files, it
might be easy to write a small utility that performs this task for you. It
may even be possible to do it in a streaming fashion without the need for a
temporary location.

Signature
Ian Shef 805/F6 * These are my personal opinions
Raytheon Company * and not those of my employer.
PO Box 11337 *
Tucson, AZ 85734-1337 *
Roedy Green - 14 Sep 2007 21:59 GMT
>Can this be done somehow (without actually moving the file)? One
>option is to copy it before it's actually jar-ed, but this is
>"hacky" (it is a solution, though) - any other (just of curiosity)? I
>tried the mappers, but that didn't work (it says "jar doesn't support
>the nested "mapper" element.")
<!-- must spell out each extra file individually to be included in the
jar -->
<resource file="com/mindprod/bio/adano.jpg" package="com.mindprod.bio"
/>
<resource file="com/mindprod/bio/lclogo.jpg"
package="com.mindprod.bio" />
You specify where the file is, and what package you want the resource
packed under in the jar.

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Mike Kaufman - 15 Sep 2007 13:41 GMT
If you specify the files using <zipfileset>s within the <jar> task, this
has attributes for specifying a "prefix" to used on all the filenames or
the "fullpath" to be used for an individual file. Might be what you're
looking for.