How to replace a file in jar with command line in linux?

50,041

Solution 1

zip -u stuff.jar file.txt

will update file.txt in stuff.zip . Note that for -u file.txt must already exist in the zip file, and will only be overwritten if it's newer than the one in the jar.

Solution 2

what about this one

jar -uf YOURJAR.jar FILE

if the jar have a folder structure, you can keep that too

jar -uf YOURJAR.jar DIR/DIR/FILE

Look this one for more information http://docs.oracle.com/javase/tutorial/deployment/jar/update.html

Share:
50,041

Related videos on Youtube

Walter Kelt
Author by

Walter Kelt

Updated on September 17, 2022

Comments

  • Walter Kelt
    Walter Kelt over 1 year

    I have a jar, and I need to replace a class in it, at this moment, I can only open it with "archive manager" and then drag and drop the new compiled class into the jar, but I think this is really boring, if I can do with with just a command ?

    Thanks ~

    • Johan
      Johan over 13 years
      +1 for gui being boring :), but you should correct "archive manager"...
  • Olivier.Roger
    Olivier.Roger over 13 years
    great tip. you could probably do it with 7-zip also.
  • Zlab
    Zlab over 6 years
    Is there a solution if zip and jar are not available? I have only tar and gzip available