Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Adding/deleting Jar entries?

Reply
Thread Tools

Adding/deleting Jar entries?

 
 
Rhino
Guest
Posts: n/a
 
      02-04-2005
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


 
Reply With Quote
 
 
 
 
Lee Fesperman
Guest
Posts: n/a
 
      02-04-2005
Rhino wrote:
>
> 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.

--
Lee Fesperman, FFE Software, Inc. (http://www.firstsql.com)
================================================== ============
* The Ultimate DBMS is here!
* FirstSQL/J Object/Relational DBMS (http://www.firstsql.com)
 
Reply With Quote
 
 
 
 
Rhino
Guest
Posts: n/a
 
      02-04-2005

"Lee Fesperman" <> wrote in message
news:...
> Rhino wrote:
> >
> > 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.
>

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


 
Reply With Quote
 
Tor Iver Wilhelmsen
Guest
Posts: n/a
 
      02-04-2005
"Rhino" <> writes:

> 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.
 
Reply With Quote
 
Rhino
Guest
Posts: n/a
 
      02-04-2005

"Tor Iver Wilhelmsen" <> wrote in message
news:...
> "Rhino" <> writes:
>
> > 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.


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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
java -cp a.jar -jar b.jar => Works on Windows, not on Debian cyberco Java 4 02-14-2006 06:27 AM
jaas.jar, jta.jar jdbc-stdext.jar missing from jdk1.5 RPM muttley Java 0 10-20-2005 02:40 PM
Differences of xercesImpl.jar, xercesImpl-J.jar, dom3-xercesImpl.jar ? Arnold Peters Java 0 01-05-2005 10:59 PM
Differences of xercesImpl.jar, xercesImpl-J.jar, dom3-xercesImpl.jar ? Arnold Peters XML 0 01-05-2005 10:59 PM
Jar file cannot find main class - gfSetup.jar (0/1) James Alan Farrell Java 6 01-09-2004 12:40 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57