replace files in a jar...

Discussion in 'Java' started by David N. Welton, Nov 5, 2005.

  1. I can't seem to find a way to force this:

    [jar] org/hecl/BasicMathCmd.class omitted as
    org/hecl/BasicMathCmd.class is up to date.

    [jar] org/hecl/EqualsCmd.class omitted as org/hecl/EqualsCmd.class
    is up to date.

    [jar] org/hecl/IntThing.class omitted as org/hecl/IntThing.class
    is up to date.

    I want these to always be replaced. Is there a way to get ant to do
    this? So far I have:

    <jar destfile="Hecl.jar" basedir="build/float" update="true"/>

    I don't see any options in the documentation that seem like they'll do
    what I want... any ideas on how to get around this problem?

    Thanks!
    --
    David N. Welton
    - http://www.dedasys.com/davidw/

    Linux, Open Source Consulting
    - http://www.dedasys.com/
     
    David N. Welton, Nov 5, 2005
    #1
    1. Advertising

  2. David N. Welton

    zero Guest

    "David N. Welton" <> wrote in news:436d00dd$0$6007
    $:

    > I can't seem to find a way to force this:
    >
    > [jar] org/hecl/BasicMathCmd.class omitted as
    > org/hecl/BasicMathCmd.class is up to date.
    >
    > [jar] org/hecl/EqualsCmd.class omitted as org/hecl/EqualsCmd.class
    > is up to date.
    >
    > [jar] org/hecl/IntThing.class omitted as org/hecl/IntThing.class
    > is up to date.
    >
    > I want these to always be replaced. Is there a way to get ant to do
    > this? So far I have:
    >
    > <jar destfile="Hecl.jar" basedir="build/float" update="true"/>
    >
    > I don't see any options in the documentation that seem like they'll do
    > what I want... any ideas on how to get around this problem?
    >
    > Thanks!


    I don't know about ant, but if I remember correctly you can't replace files
    inside a jar without recreating the complete jar. This is because of the
    format of jars.
     
    zero, Nov 5, 2005
    #2
    1. Advertising

  3. David N. Welton

    Rhino Guest

    "zero" <> wrote in message
    news:Xns9705D2D51885Fzerothishi@195.130.132.70...
    > "David N. Welton" <> wrote in news:436d00dd$0$6007
    > $:
    >
    > > I can't seem to find a way to force this:
    > >
    > > [jar] org/hecl/BasicMathCmd.class omitted as
    > > org/hecl/BasicMathCmd.class is up to date.
    > >
    > > [jar] org/hecl/EqualsCmd.class omitted as org/hecl/EqualsCmd.class
    > > is up to date.
    > >
    > > [jar] org/hecl/IntThing.class omitted as org/hecl/IntThing.class
    > > is up to date.
    > >
    > > I want these to always be replaced. Is there a way to get ant to do
    > > this? So far I have:
    > >
    > > <jar destfile="Hecl.jar" basedir="build/float" update="true"/>
    > >
    > > I don't see any options in the documentation that seem like they'll do
    > > what I want... any ideas on how to get around this problem?
    > >
    > > Thanks!

    >
    > I don't know about ant, but if I remember correctly you can't replace

    files
    > inside a jar without recreating the complete jar. This is because of the
    > format of jars.


    I've always believed that there is no way to delete or replace an entry from
    a zip or a jar. As far as I knew, you have to create a new jar that has the
    desired files in it.

    However, according to the Ant user manual,
    http://ant.apache.org/manual/index.html, the Jar and Zip tasks have an
    'update' flag. Apparently:

    ---
    The update parameter controls what happens if the ZIP file already exists.
    When set to yes, the ZIP file is updated with the files specified. (New
    files are added; old files are replaced with the new versions.) When set to
    no (the default) the ZIP file is overwritten if any of the files that would
    be added to the archive are newer than the entries inside the archive.

    [The update parameter is supposed to behave the same for the Jar task as for
    the Zip task.]
    ---

    Unfortunately, the examples in the articles for the Zip and Jar tasks are
    not very helpful. Perhaps the original poster should ask on the ant user
    mailing list? That is a fairly active list and some very experienced Ant
    users hang out there to help. This page - http://ant.apache.org/mail.html -
    gives instructions on joining the mailing list. A search of the Ant archives
    for the 'user' list might also turn up useful information. You can access
    that archive at the same page and search the archive for keywords.

    Or maybe someone will come along who has used the update flag in a Jar task
    who can explain what the original poster is doing wrong.

    The only possibility that occurs to me is based on this sentence from both
    the Jar and Zip tasks:

    ---
    Please note that ZIP files store file modification times with a granularity
    of two seconds. If a file is less than two seconds newer than the entry in
    the archive, Ant will not consider it newer.
    ---

    Is it possible that the new versions of the files that are to be replaced in
    the jar have two seconds or less difference in their timestamps?

    Rhino
     
    Rhino, Nov 6, 2005
    #3
  4. David N. Welton

    eai-notes

    Joined:
    Feb 28, 2010
    Messages:
    1
    Location:
    San Francisco Bay Area
    modifying JAR files

    One has to use the JAR utility that comes bundled with JDK to modify JARS ..for example, to change a class file. You cannot use programs like WinZIP/WinRAR.

    This post has more details:
    eai-notes.blogspot.com/2010/02/modifying-jar-files.html

    thanks,
    Aj
     
    eai-notes, Feb 28, 2010
    #4
    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. Eric McIntyre

    Jar files in Jar files

    Eric McIntyre, May 24, 2004, in forum: Java
    Replies:
    1
    Views:
    509
    Roedy Green
    May 24, 2004
  2. Arnold Peters
    Replies:
    0
    Views:
    643
    Arnold Peters
    Jan 5, 2005
  3. muttley
    Replies:
    0
    Views:
    2,802
    muttley
    Oct 20, 2005
  4. cyberco
    Replies:
    4
    Views:
    3,881
    Roedy Green
    Feb 14, 2006
  5. Arnold Peters
    Replies:
    0
    Views:
    709
    Arnold Peters
    Jan 5, 2005
Loading...

Share This Page