I created a sample spring-boot project on my mac. But when I try to run maven commands on it (such as mvn spring-boot:run
), I get the following error:
Exception in thread "main" java.lang.UnsupportedClassVersionError:
org/apache/maven/cli/MavenCli : unsupported major.minor version 51.0
followed of course by the obligatory stack trace. I know from reading answers on many other similar (but not identical) questions, that this has something to do with compiling with a more recent version of Java, and then running with an earlier version of Java. According to this chart:
J2SE 8 = 52
J2SE 7 = 51
J2SE 6.0 = 50
J2SE 5.0 = 49
JDK 1.4 = 48
JDK 1.3 = 47
JDK 1.2 = 46
JDK 1.1 = 45
I must have somehow compiled with Java 7, and then somehow run with Java 6. But I don't understand how this can be so. I'm pretty sure I'm using Java 8. For one thing, when I enter java -version
in the terminal, I get:
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)
Also, my pom clearly specifies to use Java 8:
<project>
<!-- project info -->
<name>springboot-demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<!-- dependencies -->
</project>
All the answers I've read so far say to compile with Java 6, or to just use Java 8... but I am using Java 8! Also, since the error I'm getting says "51.0" instead of "52.0", doesn't that mean I'm compiling with Java 7? As far as I know, I am only using Java 8!
Most importantly, how do I fix this?