1

I am working on a Java application. Essentially, it picks a .jar file and then inserts some files into it.

I am using the answer from Updating .JAR's contents from code. However, it is slow because it is literally make a brand new file and manually copying all the files (including the old ones) into it!

I find this strange. Is it not possible to modify a .jar file without create a whole new one?

Community
  • 1
  • 1
Saturn
  • 17,888
  • 49
  • 145
  • 271

1 Answers1

0

No. It's a ZIP file, and these are sequential in nature. All the tools that update them do so by copying, and you have to do the same.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • 1
    Not true: http://superuser.com/questions/647674/is-there-a-way-to-edit-files-inside-of-a-zip-file-without-explicitly-extracting – Donald_W Mar 04 '15 at 23:55
  • @DonaldW That question isn't even relevant: it's about editing single files rather than adding new ones, which is what this one is about. And I don't see anything there that contradicts this answer, just the use of tools, which behave as I've described above. – user207421 Mar 05 '15 at 00:17
  • The statement that 'all tools that update them do so by copying is simly not true. http://stackoverflow.com/questions/2223434/appending-files-to-a-zip-file-with-java – Donald_W Mar 05 '15 at 00:24
  • @DonaldW I don't see any actual evidence there, other than several statements that agree with me and give cogent reasons such as the directory being at the end of the file. You don't know how these virtualization APIs work under the hood. Re editing individual files you also need to think about the CRC, which is in the directory. – user207421 Mar 05 '15 at 00:37
  • I have managed to update a .JAR file without copying it or recreating its contents. I used Java's Zip File System: http://docs.oracle.com/javase/7/docs/technotes/guides/io/fsp/zipfilesystemprovider.html – Saturn Mar 13 '15 at 16:09