replace files in a jar...

  • Thread starter David N. Welton
  • Start date
D

David N. Welton

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/
 
Z

zero

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

Rhino

zero said:
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
 
Joined
Feb 28, 2010
Messages
1
Reaction score
0
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
 

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,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top