How can I add files to a Jar file?

后端 未结 9 889
自闭症患者
自闭症患者 2020-12-15 19:20

I want to add a series of files previously extracted from other files(already done) to a jar. These files will be overwriting files inside the JAR. What is the most efficien

9条回答
  •  清歌不尽
    2020-12-15 20:12

    Just to add to the existing answers, there is at least one special case: so-called executable JAR files. If you add another JAR file as a dependency -- whether you use jar or zip -- it will complain that the embedded file is compressed:

    Caused by: java.lang.IllegalStateException: Unable to open nested entry 'BOOT-INF/lib/file.jar'. It has been compressed and nested jar files must be stored without compression. Please check the mechanism used to create your executable jar file
    

    The solution to this is to use the 0 option to jar:

    jar uvf0 myfile.jar BOOT-INF/lib/file.jar
    

    You don't need this for normal class files.

提交回复
热议问题