Updating file in a jar throws ZipException

后端 未结 3 519
小蘑菇
小蘑菇 2021-01-18 00:13

I\'m trying to update a file in an existing jar (in this example antlr) using the command:

jar -uf antlrworks-1.2.3.jar org/antlr/codegen/templates/Java/Java         


        
3条回答
  •  不思量自难忘°
    2021-01-18 00:51

    You're trying to do the right thing, but the jar file is problematic - it's got the same entry twice :( (This is legal for a zip file, but not really helpful - and as you can see, it makes jar complain.)

    If you run

    jar tvf antlrworks-1.2.3.jar > contents
    

    and then look at the generated contents file you'll see that there are various duplicate files. You should probably report this to the antlr project (after checking they don't already know).

    As a workaround, you can extract the contents of the jar file, jar it up again, and then you'll have a "working" jar file you can update. (If you only need to do this once, you can just extract, put the file you want in there, and then jar the whole lot up rather than updating it afterwards.)

提交回复
热议问题