1

Details

Exception in thread "main" java.lang.UnsupportedClassVersionError: com/mysql/cj/jdbc/Driver : Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:278)

System:

Windows 64

Platform:

Eclipse Neon.1

Maven 3

Java

java 1.8 and java 1.7 both installed

JAVA_HOME point at 1.8 jdk PATH = %PATH%;%JAVA_HOME%/bin/

Eclipse execution Java application

path\to\Java\jdk1.7.0_80\bin\javaw.exe

Eclipse project build path

JRE System Library [JavaSE-1.7]

Maven Dependencies

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.2.RELEASE</version>
  </parent>

  <groupId>com.worldline.cn.workbench</groupId>
  <artifactId>orm-base</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>orm-base</name>
  <description>orm-base</description>

    <properties>
        <java.version>1.7</java.version>
    </properties>

  <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.3.1</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.4.1</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>6.0.5</version><!--$NO-MVN-MAN-VER$-->
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <version>1.5.2.RELEASE</version>
            <scope>test</scope>
        </dependency>

    </dependencies> 


    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

Anything needed?

I know this happens usually because:

A project is compiled by java 1.8, but executed by java 1.7 (or lower).

But I checked my Eclipse,

Java Compiler:

checked *use compliance from execution environment 'Java SE-1.7' on the 'Java Build Path'*

checked *enable project specific settings*

Run configuration:

JRE tab:

    Runtime JRE:

        checked: *Project execution environment 'JavaSE-1.7'(jdk1.7.0_80)*

So you see, I compiled the project with 1.7 and run it with 1.7...

cinqS
  • 1,175
  • 4
  • 12
  • 32
  • Hi, Scary Wombat, this is not the same question at all, I bet you didn't even read my question. – cinqS Mar 22 '17 at 06:21
  • Yes, I read your question *Anything needed?* – Scary Wombat Mar 22 '17 at 06:22
  • *Java SE 8 = 52* so check the version of the mysql jar – Scary Wombat Mar 22 '17 at 06:33
  • Ok, So you see, this quesiton is not the same with the others? could you please cancel the downvote of the question? – cinqS Mar 22 '17 at 06:37
  • I do not have control over other people AND basically it is the same question. – Scary Wombat Mar 22 '17 at 06:38
  • see https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-versions-java.html – Scary Wombat Mar 22 '17 at 06:45
  • 1
    Okay...... @ScaryWombat, you are right, it is because the *mysql-connecter-java*. the version 6 onward compiled with java 1.8... So I changed to the version 5.1.41. Could you plz answer with this question as an answer, So I can accept you answer. I know you may think this is naive, but believe me, sooner or later, there will be people have the same doubt. and your answer would save their time. – cinqS Mar 22 '17 at 06:46
  • See answer below - cute monkey – Scary Wombat Mar 22 '17 at 06:51

2 Answers2

2

The version of the mysql jar is compiled for JDK1.8

See this link to obtain the correct version

e.g.

Connector/J version JRE Supported
5.1                 1.5.x, 1.6.x, 1.7.x*, 1.8.x**
Scary Wombat
  • 44,617
  • 6
  • 35
  • 64
-1

Your compiler is pointing to JDK 1.8 and your runtime is JDK 1.7...You can change the java compiler configuration of the project. 1. in Eclipse -> Right Click on the Project -> Java Compiler -> Use the compiler version same as execution environment.