Corrupt jar file

后端 未结 12 1066
伪装坚强ぢ
伪装坚强ぢ 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.

    0 讨论(0)
  • 2020-11-30 04:14

    As I just came across this topic I wanted to share the reason and solution why I got the message "invalid or corrupt jarfile":

    I had updated the version of the "maven-jar-plugin" in my pom.xml from 2.1 to 3.1.2. Everything still went fine and a jar file was built. But somehow it obviously wouldn't run anymore.

    As soon as i set the "maven-jar-plugin" version back to 2.1 again, the problem was gone.

    0 讨论(0)
  • 2020-11-30 04:15

    It can be something so silly as you are transferring the file via FTP to a target machine, you go and run the .JAR file but this was so big that it has not yet been finished transferred :) Yes it happened to me..

    0 讨论(0)
  • 2020-11-30 04:19

    Also, make sure that the java version used at runtime is an equivalent or later version than the java used during compilation

    0 讨论(0)
  • 2020-11-30 04:21

    This will happen when you doubleclick a JAR file in Windows explorer, but the JAR is by itself actually not an executable JAR. A real executable JAR should have at least a class with a main() method and have it referenced in MANIFEST.MF.

    In Eclispe, you need to export the project as Runnable JAR file instead of as JAR file to get a real executable JAR.

    Or, if your JAR is solely a container of a bunch of closely related classes (a library), then you shouldn't doubleclick it, but open it using some ZIP tool. Windows explorer namely by default associates JAR files with java.exe, which won't work for those kind of libary JARs.

    0 讨论(0)
  • 2020-11-30 04:21

    The problem might be that there are more than 65536 files in your JAR: Why java complains about jar files with lots of entries? The fix is described in this question's answer.

    0 讨论(0)
提交回复
热议问题