Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

I typed in "java -jar ShowTime.jar", and got 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 should I fix this? P.S. I have a mac.

like image 856
user858819 Avatar asked Jul 22 '11 23:07

user858819


2 Answers

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

like image 81
fvu Avatar answered Oct 15 '22 03:10

fvu


That usually means that you compiled the jar for a newer version of java than you ran it with. Check to see if you are using the same version of java to compile and run. If that doesn't fix the problem, please provide more info such as the compiler command and the output of java -version.

like image 20
Jon7 Avatar answered Oct 15 '22 03:10

Jon7