Question

I'm developing a web project in Java 6 with Netbeans 8. I recently decided to switch from JUnit to TestNG in the most standard way possible: the TestNG library is automatically enabled when I add a TestNG Test Case to my Netbeans project ...

... And now I can't build my project anymore. The error is:

java.lang.UnsupportedClassVersionError: org/testng/TestNG : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
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:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: org.testng.TestNG.  Program will exit.

When I change the Java Platform in Netbeans to Java 7 (default), the build succeeds and my tests work as they should. From searching online, it turns out that Java version 51 = Java 7. When I went sniffing around in the testng-dist.jar file, it looked like the build I have was compiled with JDK 7:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.4
Created-By: 1.7.0_17-b02 (Oracle Corporation)
Main-Class: org.testng.TestNG
Implementation-Version: 6.8.1-201304241555

But when I use the alternative technique specified here, I find that it was compiled for Java 1.5:

ca fe ba be 20 20 20 **31** 20 13 01 20 03 28 29 56

(0x31 = 49 = Java 1.5)

So unless I'm misunderstanding things, there's no reason why my setup shouldn't work.

My build.xml and build-impl.xml are both completely standard, because I haven't changed anything manually. I am not willing to migrate to Java 7, and I am sure that I want to use TestNG if at all possible. I have tried building the TestNG source from the Git repo, but that failed because I have absolutely no experience with Ant (or Maven, for that matter). Turns out I'm kind of lost at sea here.

Was it helpful?

Solution

I'll answer my own question for future reference. There are multiple ways I've tried to get around this, but it doesn't seem to be possible to get it to work on Java 6.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top