This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 198664 - Maven Junit does not run on code change java.lang.UnsupportedClassVersionError t : Unsupported major.minor version 51.0
Summary: Maven Junit does not run on code change java.lang.UnsupportedClassVersionErr...
Status: RESOLVED DUPLICATE of bug 201938
Alias: None
Product: projects
Classification: Unclassified
Component: Maven (show other bugs)
Version: 7.0.1
Hardware: PC Windows 7 x64
: P1 normal (vote)
Assignee: Jesse Glick
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-17 06:52 UTC by mohan_82
Modified: 2011-09-19 18:09 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description mohan_82 2011-05-17 06:52:02 UTC
Hi I have made sure I m pointing to JDK 1.6 in my project, I did mvn clean install, ran junit it is fine but if I change something and try to run test again I get the following error,
st : Unsupported major.minor version 51.0
java.lang.UnsupportedClassVersionError: com/creative/finance/equities/daoimpl/StockSymbolInfoDaoImplTest : Unsupported major.minor version 51.0
	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)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:169)

Looks like Junit is pointing to JDK 1.7 some where ..Help please !! This occurs in IDE 7 and daily build but not in 6.9.1 version.

Product Version = NetBeans IDE Dev (Build 201105160400)
Operating System = Linux version 2.6.38-8-generic-pae running on i386
Java; VM; Vendor = 1.6.0_24
Runtime = Java HotSpot(TM) Client VM 19.1-b02
Comment 1 Yulia Novozhilova 2011-08-11 13:08:50 UTC
Jesse, could you please take a look. Looks like some problem in maven project configuration. Thanks!
Comment 2 Jesse Glick 2011-08-11 16:46:18 UTC
I cannot diagnose the issue without steps to reproduce it from scratch. Possibly a project misconfiguration. It seems you are running the IDE itself on JDK 6 so somewhere you must be referring to JDK 7. http://jira.codehaus.org/browse/SUREFIRE-447 is similar. Be sure to specify the source and target level in maven-compiler-plugin configuration.
Comment 3 joshualbailey 2011-09-15 19:15:31 UTC
I'm having the same issue with 7.0.1, so I purged my machine of anything related to Java, made sure nothing was pointing to 1.7 in the xml or project files, restarted, and installed a fresh JDK 1.6.0_26 executable, but it does not fix the problem. It occurs when I run JUnit tests in the IDE.


cd C:\Users\user\Documents\NetBeansProjects\Platform\sites; "JAVA_HOME=C:\\Program Files\\Java\\jdk1.6.0_26" "\"C:\\Program Files\\NetBeans 7.0.1\\java\\maven\\bin\\mvn.bat\"" test
Scanning for projects...
                                                                        
------------------------------------------------------------------------
Building Sites 00.01.01-SNAPSHOT
------------------------------------------------------------------------

[resources:resources]
Using 'UTF-8' encoding to copy filtered resources.
Copying 0 resource

[compiler:compile]
Compiling 3 source files to C:\Users\user\Documents\NetBeansProjects\Platform\sites\target\classes

[resources:testResources]
Using 'UTF-8' encoding to copy filtered resources.
Copying 0 resource

[compiler:testCompile]
Nothing to compile - all classes are up to date

[surefire:test]
Surefire report directory: C:\Users\user\Documents\NetBeansProjects\Platform\sites\target\surefire-reports
java.lang.reflect.UndeclaredThrowableException
	at $Proxy0.invoke(Unknown Source)
	at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:150)
	at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcess(SurefireStarter.java:91)
	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:69)
Caused by: java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.apache.maven.surefire.booter.ProviderFactory$ClassLoaderProxy.invoke(ProviderFactory.java:103)
	... 4 more
Caused by: java.lang.UnsupportedClassVersionError: com/thebookgrove/sites/AlibrisTest : 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)
	at org.apache.maven.surefire.util.DefaultDirectoryScanner.loadClass(DefaultDirectoryScanner.java:105)
	at org.apache.maven.surefire.util.DefaultDirectoryScanner.locateTestClasses(DefaultDirectoryScanner.java:78)
	at org.apache.maven.surefire.junit4.JUnit4Provider.scanClassPath(JUnit4Provider.java:164)
	at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:86)
	... 9 more
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 8.308s
Finished at: Thu Sep 15 11:53:02 MST 2011
Final Memory: 15M/173M
------------------------------------------------------------------------
Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.7.2:test (default-test) on project sites: There are test failures.

Please refer to C:\Users\user\Documents\NetBeansProjects\Platform\sites\target\surefire-reports for the individual test results.
-> [Help 1]

To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.

For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
Comment 4 mohan_82 2011-09-16 00:26:07 UTC
Hi Joshua,
I managed to find why I was getting,
st : Unsupported major.minor version 51.0
java.lang.UnsupportedClassVersionError:
com/creative/finance/equities/daoimpl/StockSymbolInfoDaoImplTest : Unsupported
major.minor version 51.0

The issue was Netbeans maven plugin could not understand properties in my maven compiler plugin.
ie In my Maven compiler plugin configuration, I was setting,
<src>{$java.version}</src><target>{$java.version}</target>.

This configuration is not propagated to Netbeans platform project.properties. Change you pom.xml to <src>1.6</src><target>1.6</target> build and try running your test it should be fine. I have raised separate issue for that, for your info

http://netbeans.org/bugzilla/show_bug.cgi?id=201938
Regards,
Mohan
Comment 5 joshualbailey 2011-09-16 17:13:08 UTC
Thanks for responding!

I'm using:
Product Version: NetBeans IDE 7.0.1 (Build 201107282000)
Java: 1.6.0_26; Java HotSpot(TM) 64-Bit Server VM 20.1-b02
System: Windows 7 version 6.1 running on amd64; Cp1252; en_US (nb)

I tried setting 1.6 explicitly as you mentioned, but this still did not fix the problem. However, I did finally find the culprit...

If you right click on the project -> Properties -> Build -> Compile, set "Compile on Save" to Disable, it's fixed! Mine was set to "For test execution only." for some reason, which explains why I was able to Run and Debug just fine, but could not run Unit tests...

I tried this while using the ${java.version} variable for <source> and <target> and it works!
Comment 6 Jesse Glick 2011-09-19 18:09:48 UTC
(In reply to comment #5)
> If you right click on the project -> Properties -> Build -> Compile, set
> "Compile on Save" to Disable, it's fixed! Mine was set to "For test execution
> only." for some reason

That is the default, since it is faster (avoids running Maven during the edit-test cycle). For unusual project setups you can disable CoS. Bug #201938 sounds like the root issue - the IDE did not interpolate your source level, so the IDE-compiled classes used -source 7 (and implicitly -target 7) whereas the actual test run used the project's configured JDK 6.

*** This bug has been marked as a duplicate of bug 201938 ***