Corrupt jar file

后端 未结 12 1116
伪装坚强ぢ
伪装坚强ぢ 2020-11-30 03:42

I have created a jar file in windows 7 using eclipse. When I am trying to open the jar file it says invalid or corrupt jar file. Can anyone suggest me why the jar file is in

12条回答
  •  自闭症患者
    2020-11-30 04:08

    If the jar file has any extra bytes at the end, explorers like 7-Zip can open it, but it will be treated as corrupt. I use an online upload system that automatically adds a single extra LF character ('\n', 0x0a) to the end of every jar file. With such files, there are a variety solutions to run the file:

    • Use prayagubd's approach and specify the .jar as the classpath and name of the main class at the command prompt
    • Remove the extra byte at the end of the file (with a hex-editor or a command like head -c -1 myjar.jar), and then execute the jar by double-clicking or with java -jar myfile.jar as normal.
    • Change the extension from .jar to .zip, extract the files, and recreate the .zip file, being sure that the META-INF folder is in the top-level.
    • Changing the .jar extension to .zip, deleting an uneeded file from within the .jar, and change the extension back to .jar

    All of these solutions require that the structure of the .zip and the META-INF file is essentially correct. They have only been tested with a single extra byte at the end of the zip "corrupting" it.

    I got myself in a real mess by applying head -c -1 *.jar > tmp.jar twice. head inserted the ASCII text ==> myjar.jar <== at the start of the file, completely corrupting it.

提交回复
热议问题