Adding/deleting Jar entries?

Discussion in 'Java' started by Rhino, Feb 4, 2005.

  1. Rhino

    Rhino Guest

    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
    Rhino, Feb 4, 2005
    #1
    1. Advertising

  2. 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)
    Lee Fesperman, Feb 4, 2005
    #2
    1. Advertising

  3. Rhino

    Rhino Guest

    "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
    Rhino, Feb 4, 2005
    #3
  4. "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.
    Tor Iver Wilhelmsen, Feb 4, 2005
    #4
  5. Rhino

    Rhino Guest

    "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
    Rhino, Feb 4, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Arnold Peters
    Replies:
    0
    Views:
    564
    Arnold Peters
    Jan 5, 2005
  2. muttley
    Replies:
    0
    Views:
    2,714
    muttley
    Oct 20, 2005
  3. cyberco
    Replies:
    4
    Views:
    3,748
    Roedy Green
    Feb 14, 2006
  4. Arnold Peters
    Replies:
    0
    Views:
    653
    Arnold Peters
    Jan 5, 2005
  5. Don Bruder
    Replies:
    3
    Views:
    965
    spikeysnack
    Aug 3, 2010
Loading...

Share This Page