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

后端 未结 3 1533
感情败类
感情败类 2020-12-02 07:38

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

相关标签:
3条回答
  • 2020-12-02 07:57
    zip -d file.jar unwanted_file.txt
    

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

    0 讨论(0)
  • 2020-12-02 08:00

    In case you want to delete file in order to unsign signed jar, you can probably just make the .RSA file zero-sized. This can be accomplished with just jar u. See https://stackoverflow.com/a/24678645/653539 . (Worked for me, though I admit it's hack.)

    0 讨论(0)
  • 2020-12-02 08:13

    In Java you can copy all the entries of a jar except the one you want to delete. i.e. you have to make a copy but don't need to create the individual files.

    You can do this by

    • creating a new jar.
    • iterating though the Jar you have
    • copy the entry from one jar to the other, skipping any files you want.
    • close and replace the orginal jar if you want.
    0 讨论(0)
提交回复
热议问题