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

kellyfj picture kellyfj · Dec 23, 2010 · Viewed 88.8k times · Source

So I need to remove a file from a jar / war file. I was hoping there was something like "jar -d myjar.jar file_I_donot_need.txt"

But right now the only way I can see of doing this from my Linux command line (without using WinRAR/Winzip or linux equivalent) is to

  • Do "jar -xvf" and extract the
    complete Jar file
  • Remove the file(s) I don't need
  • Rejar the jar file using "jar -cvf"

Please tell me there is a shorter way?

Answer

martona picture martona · Dec 23, 2010
zip -d file.jar unwanted_file.txt

jar is just a zip file after all. Definitely much faster than uncompressing/recompressing.