#2086 UnsupportedClassVersionError: Bad version number in .class file

ortizgiraldo Mon 21 Jan 2013

Hi All, I'm trying to generate an executable jar file compatible with Java 5. I'm running Java 6 in my computer but I need to run the jar in a server running Java 5. The jar compiles and runs perfectly in my local environment but as soon as I try to run it on the server I get:

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(ClassLoader.java:621)
      at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
      at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
      at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
      at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)

I read topic 1765 but that only applies to Java 7 which I'm not running.

The Java version in the server is:

java version "1.5.0_26"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_26-b03)
Java HotSpot(TM) Server VM (build 1.5.0_26-b03, mixed mode)

My local Java version is:

java version "1.6.0_38"
Java(TM) SE Runtime Environment (build 1.6.0_38-b05)
Java HotSpot(TM) Client VM (build 20.13-b02, mixed mode, sharing)

And my Fantom environment is:

Java Runtime:
  java.version:    1.6.0_38
  java.vm.name:    Java HotSpot(TM) Client VM
  java.vm.vendor:  Sun Microsystems Inc.
  java.vm.version: 20.13-b02
  java.home:       C:\Program Files\Java\jre6
  fan.platform:    win32-x86
  fan.version:     1.0.64
  fan.env:         sys::BootEnv
  fan.home:        D:\dev\fan

Any ideas will be greatly appreciated. Thank you.

JonasL Mon 21 Jan 2013

This happens when you build source with a later version of java and try to run it with an older jre.

You need to supply javac with -target 1.5 in your local env when building whatever you're trying to deploy.

See here for more info

ortizgiraldo Tue 22 Jan 2013

The -target 1.5 parameter is already being passed to javac in CompileJava.fan. I edited and recompiled that class following the steps described in 1765. I did it for adding the -bootclasspath and -extdirs as recommended in the Java documentation link given by JonasL but still didn't work (thanks anyway), so I restored the CompileJava.fan included in v1.0.64

What did the trick for me was to set the jdkHome in %FAN_HOME%\etc\build\config.props to point to a JDK v1.5, e.g.

jdkHome=/C:/Program Files/Java/jdk1.5.0_17/

I hope this helps others.

Login or Signup to reply.