Writing into a JAR

Im working on a simple little application which has a need for a few small external roperties. Im planning on using Property class in conjuction with a property file.

Now I want to make an executable jar file. Reading in a File from a jar is not a big deal, using getResourceAsStream() method... The config file is obviously not going to be readily available for modifications, instead will have a gui for changing the values, launched from the application... Is it possible to write back into the jar? Ive started to do a few tests but Im not making much progress at this point, and Im hoping someone can stear me in the right direction on this....

[669 byte] By [J.Prisco] at [2007-9-26 6:57:28]
# 1
Well I think I got it, a little quicker than I had expected..Still if anyone has any imput on this topic Id apreciate it...
J.Prisco at 2007-7-1 16:30:30 > top of Java-index,Core,Core APIs...
# 2
if u found a reasonable solution plis share it with mekind regards
pwrzsi at 2007-7-1 16:30:30 > top of Java-index,Core,Core APIs...
# 3
I have the same problem. Could anyone please help?
ClemensE at 2007-7-1 16:30:30 > top of Java-index,Core,Core APIs...
# 4
I can't figure out how to update the JAR while use the java.util.jar.* packages, It is possible to do it manually: http://forum.java.sun.com/thread.jsp?forum=4&thread=391882
_nuhb_ at 2007-7-1 16:30:30 > top of Java-index,Core,Core APIs...
# 5

As I said in that thread, you can't. And the reason you can't figure out how to do it, is because the java.util.jar package only supports writing sequentially, not randomly.

People subsequently posted links to some documents that suggested you could "update" a jar, for example by using the "jar uf ..." command. I think you'll find that command actually creates a new jar file, building the contents from the old jar file and the files specified for update. It's fair to call this "updating" the file, I suppose. You could do that too.

DrClap at 2007-7-1 16:30:30 > top of Java-index,Core,Core APIs...
# 6
i think he/she was asking how to wrtie to/read from a file in a jar. why should this be such a difficult job? are you making too big a fuss about it?
daFei at 2007-7-1 16:30:30 > top of Java-index,Core,Core APIs...
# 7

> [writing to a jar] why should this be such a difficult job?

Coz of the zip files work, they are a compressed stream of files, with each file following on from the last, to write any data into any of the files, you would have to then shift all the files following the file you have just writen too. You would then have to rewrite the zip files internal file alication table.

Next is the way ZIP files compress (it has been a long time sence I've done anything major with ZIP files (other than use 'em from an end-user POV, so this could be wrong;), zip look for repeating pattens in the stream, and then if it repeat a few times, it replaces the set of data with one item of data (ok, that kind of made sence in my head, lets see if an example will help:

11112111112 could be replaced with: A2A12, and a rules stating A == 1111. If you change the files in the ZIP file, then you could have rules that no longer apply (making the zip file larger).

It would still be nice to have all the decompression/temp files/compression done for you in a nice API thou. :)

mlk at 2007-7-1 16:30:30 > top of Java-index,Core,Core APIs...
# 8
yeah, it does look complicated. thought there are some apis that allow you to work on jars... i myself was planning to put some properties files in a jar that will be modified later on. now i think i need to change this design. thanks for the input.
daFei at 2007-7-1 16:30:30 > top of Java-index,Core,Core APIs...