1

I have created a jar file using eclipse. My jdk version is 1.5.0. when i run that jar file on linux machine with the same JDK it works fine. But when I run this jar on solaris machine with JDK 1.5.0_14 installed it gives error as

Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)

I couldn't get any solution..?

StoopidDonut
  • 8,547
  • 2
  • 33
  • 51
Pratik
  • 109
  • 1
  • 5
  • 14
  • Usually such exception arise when you compile higher version and running it in lower version of java. – Kick Jan 29 '14 at 09:37
  • I know you already told us the version, but can you post the result of `java -version` on both linux and solaris machine? – BackSlash Jan 29 '14 at 09:38
  • And also, remember that not always the same java that runs eclipse is the java that was used by eclipse to compile the app – Leo Jan 29 '14 at 09:40
  • `'which java' -version` (and replace ticks with backticks)? – Anders R. Bystrup Jan 29 '14 at 09:42
  • Beautifully answered here: http://stackoverflow.com/questions/2466828/java-lang-unsupportedclassversionerror-bad-version-number-in-class-file – user1933888 Jan 29 '14 at 09:44
  • on solaris java -version gives java version "1.5.0_14" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_14-b03) Java HotSpot(TM) Server VM (build 1.5.0_14-b03, mixed mode) – Pratik Jan 29 '14 at 09:50

1 Answers1

0

This happens when JVM cannot read the classfile. Since JVMs are backward compatible, i.e. support older versions of class files your class is created by compiler newer than JVM you are using.

You are using JVM 1.5, but your code was compiled by compiler of 1.6 or 1.7 (or even probably 1.8?).

So, you should either upgrade your java environment on machine where you are running the application or compile the application with 1.5 compiler. The first way is definitely preferable.

AlexR
  • 114,158
  • 16
  • 130
  • 208