3

I'm using Spring Tool Suite (basically the same as Eclipse, can't actually find a difference but I'm being made to use it) for an assignment and I'm having an error when I right click on the project and click 'Run As -> Maven Install'.

Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/maven/cli/MavenCli : Unsupported major.minor version 51.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637) at java.lang.ClassLoader.defineClass(ClassLoader.java:621) 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 org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(ClassRealm.java:401) at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42) at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271) at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:254) at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239) at org.codehaus.plexus.classworlds.launcher.Launcher.getMainClass(Launcher.java:144) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:266) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

Everything else I have found on stack exchange implies that this is something to do with the Java Version, but I can't figure out how I have it wrong. When I run mvn -version on terminal I get

Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T21:57:37+10:00)
Maven home: /usr/local/Cellar/maven/3.3.3/libexec
Java version: 1.8.0_60, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.10.4", arch: "x86_64", family: "mac"

When I run java -version I get

java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

I tried setting JAVA_HOME (as per Maven Installation OSX Error Unsupported major.minor version 51.0) and it is set to the correct path.

My STS settings say it's compiling using 1.8, and running using 1.8, and the properties of the project say it's compiling using 1.8 too. I don't understand where the problem is.

I originally tried changing everything to Java 1.7 to see if that was the problem but it still didn't help. I changed it back to 1.8 in the end because that's what the rest of my group are using.

This is my first post so I can't post screenshots, they're at the link. https://i.stack.imgur.com/0WPV5.jpg

Community
  • 1
  • 1
annedroiid
  • 6,267
  • 11
  • 31
  • 54
  • possible duplicate of [Maven Installation OSX Error Unsupported major.minor version 51.0](http://stackoverflow.com/questions/29255495/maven-installation-osx-error-unsupported-major-minor-version-51-0) – Tim Biegeleisen Sep 22 '15 at 04:22

3 Answers3

2

I fixed it by deleting Java SE 6 from the Installed JREs list in screenshot 1. Even though 8 was selected, it was still using 6 for some reason.

annedroiid
  • 6,267
  • 11
  • 31
  • 54
1

I faced the same issue, by removing .m2 repository or just renaming it, resolves the issue

Prakash Bhagat
  • 1,406
  • 16
  • 30
0

you should config JRE when execute maven build enter image description here

McGrady
  • 10,869
  • 13
  • 47
  • 69
zhuojl
  • 11
  • 1
  • Although this may answer the question consider to provide an explanation, in its current form answer is likely to be closed / downvoted. – Bond - Java Bond Apr 13 '17 at 12:19
  • it's helpful to those people who don't want to delete JRE or the .m2 dir ,and it's easier! – zhuojl Apr 14 '17 at 14:09