Adding/deleting Jar entries?

R

Rhino

Given a jar that contains entries representing files (as opposed to
directories), is it possible to add new file entries to the jar or to remove
(permanently delete) entries from the jar *programmatically*? (I know that I
can add files to a jar via the jar -u option on the command line.)

I want my program to be able to add and remove files from a jar but it's
beginning to look like the only way I can accomplish deletions is to make a
new copy of the jar and copy over everything but the file that is to be
deleted, then replace the old jar with the new one. And I may have to use
runtime.exec() to add a new file programmatically. Both options are pretty
ugly but I don't see anything useful in the API, like add() or delete()
methods in either the JarFile or JarEntry classes.

Am I missing something? If yes, please tell me the basic approach to
adding/deleting jar entries.

--
Rhino
---
rhino1 AT sympatico DOT ca
"There are two ways of constructing a software design. One way is to make it
so simple that there are obviously no deficiencies. And the other way is to
make it so complicated that there are no obvious deficiencies." - C.A.R.
Hoare
 
L

Lee Fesperman

Rhino said:
Given a jar that contains entries representing files (as opposed to
directories), is it possible to add new file entries to the jar or to remove
(permanently delete) entries from the jar *programmatically*? (I know that I
can add files to a jar via the jar -u option on the command line.)

I want my program to be able to add and remove files from a jar but it's
beginning to look like the only way I can accomplish deletions is to make a
new copy of the jar and copy over everything but the file that is to be
deleted, then replace the old jar with the new one. And I may have to use
runtime.exec() to add a new file programmatically. Both options are pretty
ugly but I don't see anything useful in the API, like add() or delete()
methods in either the JarFile or JarEntry classes.

Am I missing something? If yes, please tell me the basic approach to
adding/deleting jar entries.

You didn't miss anything. The only way to add/delete jar entries is to make a new copy
of the jar. That's what the utilities do.
 
R

Rhino

Lee Fesperman said:
You didn't miss anything. The only way to add/delete jar entries is to make a new copy
of the jar. That's what the utilities do.
Yikes! That's ugly. I guess that's one of the downsides to jars that don't
get as much attention as the benefits of jars.....

Rhino
 
T

Tor Iver Wilhelmsen

Rhino said:
Yikes! That's ugly. I guess that's one of the downsides to jars that
don't get as much attention as the benefits of jars.....

It doesn't get that much attention because you're simply not
*supposed* to write to them dynamically. So it's not really a downside
as such.
 
R

Rhino

Tor Iver Wilhelmsen said:
It doesn't get that much attention because you're simply not
*supposed* to write to them dynamically. So it's not really a downside
as such.

It sure seems like a downside to me when I want to add or files
programmatically. That doesn't seem like a particularly unreasonable thing
to want to do so that fact that jars don't support that feels negative to
me. Naturally, your mileage may vary ;-)

Rhino
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top