"ClassFormatError: Incompatible magic value" when trying to run a Java jar file

I typed "java -jar ShowTime.jar" and received this error message:

Exception in thread "main" java.lang.ClassFormatError: Incompatible magic value 1347093252 in class file ShowTime at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632) at java.lang.ClassLoader.defineClass(ClassLoader.java:616) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141) at java.net.URLClassLoader.defineClass(URLClassLoader.java:283) at java.net.URLClassLoader.access$000(URLClassLoader.java:58) at java.net.URLClassLoader$1.run(URLClassLoader.java:197) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) 

How can I fix this? PS I have a mac.

+4
source share
3 answers

The Java class should start with the value magic (hex) 0xCAFEBABE (neat huh). Your value 1347093252 is 0x504B0304 in hexadecimal, which is the magic value for the ZIP file (the first 2 bytes in ASCII are PK for Phil Katz , the creator of the ZIP format). The jar is also a zipfile btw, so your jar is probably pretty badly damaged. Try rebuilding the entire project.

+18
source

This usually means that you compiled jar for a newer version of java than you ran it. Check if you are using the same version of java to compile and run. If this does not fix the problem, provide additional information such as a compiler command and java -version .

+1
source

This means that your application uses a JAR file that is respected in a specific format on some other system. Now, when you try to use the project in another system, the other system cannot decode the bank, since each system generates a specific key for linking the project.

Remote id debugging is the best way to find a problem that is in the wrong format. Run the command at the comment prompt for remote debugging of Java -agentlib: jdwp = transport = dt_socket, server = y, address = 8001, suspend = n

You need to find the jar file and replace it with another one (maybe just downloaded or if you have a teammate. Use it.)

The error I was getting because my project had a dependency with another ABC project and ABC used a common jar. But the ABC project was bundled with a magic key. I replaced the can used by ABC with a loaded can.

0
source

Source: https://habr.com/ru/post/952431/


All Articles