Is there a quick way to delete a file from Jar / war without having to remove the jar and recreate it?

Therefore, I need to delete the file from the jar / war file. I was hoping there is something like "jar -d myjar.jar file_I_donot_need.txt"

But now the only way to see this from my Linux command line (without using WinRAR / Winzip or the Linux equivalent) is to

  • Make "jar -xvf" and extract the full jar file
  • Delete file I do not need
  • Return the jar file with "jar -cvf"

Please tell me a shorter way?

+82
java linux jar
Dec 23 '10 at 16:57
source share
3 answers
zip -d file.jar unwanted_file.txt 

jar is just a zip file. Definitely much faster than splitting / re-compressing.

+159
Dec 23 '10 at 17:11
source share

In Java, you can copy all entries to the bank except the one you want to delete. those. you need to make a copy, but you do not need to create separate files.

You can do it with

  • creation of a new can.
  • iteration although you have jar
  • copy the record from one bank to another, skipping any files you want.
  • close and replace the original jar if you wish.
+1
Dec 23 '10 at 17:09
source share

If you want to delete the file to align the signed jar, you can simply make the .RSA file null. This can only be done with jar u . See https://stackoverflow.com/a/3188268/ (Worked for me, although I admit he hacked.)

0
Jul 10 '14 at 2:08
source share



All Articles