问题
I am trying to run mvn test on my project. The project itself compiles and installs but man test fails with the following output:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.18:test (default-test) on project udms-server: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.18:test failed: There was an error in the forked process
[ERROR] java.lang.UnsupportedClassVersionError: some/project/Event : Unsupported major.minor version 52.0
[ERROR] at java.lang.ClassLoader.defineClass1(Native Method)
[ERROR] at java.lang.ClassLoader.defineClass(Unknown Source)
[ERROR] at java.security.SecureClassLoader.defineClass(Unknown Source)
[ERROR] at java.net.URLClassLoader.defineClass(Unknown Source)
[ERROR] at java.net.URLClassLoader.access$100(Unknown Source)
[ERROR] at java.net.URLClassLoader$1.run(Unknown Source)
[ERROR] at java.net.URLClassLoader$1.run(Unknown Source)
[ERROR] at java.security.AccessController.doPrivileged(Native Method)
[ERROR] at java.net.URLClassLoader.findClass(Unknown Source)
[ERROR] at java.lang.ClassLoader.loadClass(Unknown Source)
[ERROR] at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
[ERROR] at java.lang.ClassLoader.loadClass(Unknown Source)
[ERROR] at java.lang.ClassLoader.defineClass1(Native Method)
[ERROR] at java.lang.ClassLoader.defineClass(Unknown Source)
[ERROR] at java.security.SecureClassLoader.defineClass(Unknown Source)
[ERROR] at java.net.URLClassLoader.defineClass(Unknown Source)
[ERROR] at java.net.URLClassLoader.access$100(Unknown Source)
[ERROR] at java.net.URLClassLoader$1.run(Unknown Source)
[ERROR] at java.net.URLClassLoader$1.run(Unknown Source)
[ERROR] at java.security.AccessController.doPrivileged(Native Method)
[ERROR] at java.net.URLClassLoader.findClass(Unknown Source)
[ERROR] at java.lang.ClassLoader.loadClass(Unknown Source)
[ERROR] at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
[ERROR] at java.lang.ClassLoader.loadClass(Unknown Source)
[ERROR] at org.apache.maven.surefire.util.DefaultScanResult.loadClass(DefaultScanResult.java:131)
[ERROR] at org.apache.maven.surefire.util.DefaultScanResult.applyFilter(DefaultScanResult.java:95)
[ERROR] at org.apache.maven.surefire.junit4.JUnit4Provider.scanClassPath(JUnit4Provider.java:194)
[ERROR] at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:92)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
I think some/project was compiled with Java 8... so I changed my current project to use Java 8 instead of 7 as well. I'm inclined to think this relates because of these questions:
Can't fix Unsupported major.minor version 52.0 even after fixing compatibility
Unsupported major.minor version 52.0
And now I'm completely stuck :(
回答1:
Make sure your version of Maven runtime >= JRE 1.8.
Run java -version in console to check the version, if mvn command is executed in console too. Alternatively to change maven JRE in your IDE, if maven is executed in IDE.
UnsupportedClassVersionError:
Thrown when the Java Virtual Machine attempts to read a class file and determines that the major and minor version numbers in the file are not supported.
回答2:
The JVM shall be explicitly set in the plugin configuration.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<jvm>${env.JAVA_HOME}/bin/java</jvm>
</configuration>
</plugin>
回答3:
It seems I hadn't updated my Maven in Eclipse (right click project -> Maven -> Update Project...) or chosen JDK 8 in Window -> Preferences -> Java -> Compiler options. With these two done everything works perfectly again :)
来源:https://stackoverflow.com/questions/27439564/mvn-test-fails-because-of-surefire-jdk-version