1

I a new to programming and learning Java.

I am trying to package a Java Spring Boot application. When I use the command "mvnw package" I get the following error:

/watchlist/WatchlistApplicationTests has been compiled by a more recent version of the Java Runtime (class file version 55.0) , this version of the Java Runtime only recognizes class file versions up to 52.0

From reading online, I learnt that there is an issue with me using older Java version.

File version 55.0 is Java 11 and version 52.0 is Java 8.

I tried updating the Java version using the "Check for updates program". So that is fine.

When I run the "java -version" command I get the following:

openjdk version "11.0.8" 2020-07-14 LTS OpenJDK Runtime Environment Corretto-11.0.8.10.1 (build 11.0.8+10-LTS) OpenJDK 64-Bit Server VM Corretto-11.0.8.10.1 (build 11.0.8+10-LTS, mixed mode)

I then tried to change the project settings on Eclipse:

Java Build Path -> Libraries -> JRE System Library [jdk-15]

Java Compiler -> Compiler Compliance Level - 14

The POM file is a below:

<?xml version="1.0" encoding="UTF-8"?>
<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 https://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>2.4.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.openclassrooms</groupId>
    <artifactId>watchlist</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>watchlist</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>11</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

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

</project>

Not sure where I am going wrong.

Nick Sharma
  • 35
  • 1
  • 9
  • The problem is related to you have compile with some specific version of Java and try to run the application with other. There is question very similar in this post [How to fix Unsupported major.minor version](https://stackoverflow.com/questions/10382929/how-to-fix-java-lang-unsupportedclassversionerror-unsupported-major-minor-versi) . Try to modify the Compiler Compliance Level - 11 – Andres Sacco Dec 29 '20 at 01:10

1 Answers1

0

Its working fine with java 1.8. use jvm 1.8 for development

  • Other option is change "11" to "1.8" which is the default value of the parent pom – Andres Sacco Dec 29 '20 at 01:38
  • @AndresSacco I tried changing the Java version. Does not work. – Nick Sharma Dec 29 '20 at 02:16
  • Could you run the command "mvn clean compile" in the console? (In the directory of tour project). – Andres Sacco Dec 29 '20 at 02:44
  • @AndresSacco I did something and now the whole thing wont compile. Before I could run it as Spring Boot app, now it is getting terminated. – Nick Sharma Dec 29 '20 at 09:00
  • ources must not be empty at org.springframework.util.Assert.notEmpty(Assert.java:470) ~[spring-core-5.3.2.jar:5.3.2] at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:412) [spring-boot-2.4.1.jar:2.4.1] at org.springframework.boot.SpringApplication.run(SpringApplication.java:325) [spring-boot-2.4.1.jar:2.4.1] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1309) [spring-boot-2.4.1.jar:2.4.1] at org.springframework.boot.SpringApplication.main(SpringApplication.java:1325) [spring-boot-2.4.1.jar:2.4.1] //This is the error I see – Nick Sharma Dec 30 '20 at 03:02