Karthik
Karthik

Reputation: 137

UnsupportedClassVersionError while using Jmockit in a Java 1.5 Project

I am trying to use JMockit in a JUnit test, but I am getting an UnsupportedClassVersionError while running the tests from Eclipse. This is a Java 1.5 project and I have JDK 1.5.0.22 in build path and the version of JUnit in class path is 4.11 (downloaded from maven repository)

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 sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:133)

I went through the JMockit installation instructions and made the following changes;

  1. Have jmockit.jar before Junit.jar in the classpath
  2. Pass the jmockit.jar as an initialization parameter to the JVM
  3. Project uses the JRE from a JDK installation instead of a "plain" JRE

Eclipse Project specific Java Compiler Settings

Run config for Project

I have spent lot of hours trying to fix this :(, but no luck. Please let me know if you have an solution for this? What am I missing here?

Upvotes: 0

Views: 2832

Answers (1)

dcsohl
dcsohl

Reputation: 7406

You haven't specified what version of JMockit you are using; however it seems to me like you're running into this:

From this version on, JMockit requires Java 6 or newer when running tests;
JRE 1.5 is no longer supported. Note that this only applies to the JRE/JDK
used for test  execution; class files compiled  for older versions of Java
are still supported.

That's as of JMockit 1.8, released last April.

This, BTW, is to be expected, since Java 1.5 hasn't been publicly supported in over five years.

Upvotes: 2

Related Questions