Making JAR with different structure

W

wimxa

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.")
 
I

Ian Shef

(e-mail address removed) wrote in @k79g2000hse.googlegroups.com:
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)?
<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.
 
R

Roedy Green

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.
 
M

Mike Kaufman

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,217
Latest member
IRMNikole

Latest Threads

Top