Local repository class file version is incorrect and cannot be compiled

Asked 2 years ago, Updated 2 years ago, 118 views

I am developing Java environment using vscode and maven, but I am using pom.xml dependency

<dependency>
        <groupId>io.genetics</groupId>
        <artifactId> genetics</artifactId>
        <version>7.0.0</version>
    </dependency>

When I added and compiled libraries as shown in , I got the following error.

[ERROR]/c:/Users/.../demo/src/main/javamaven-3.8.5\repository\io\genetics\jenetics\7.0.0\genetics-7.0.0.jar(io/genetics/BitChromosome.class) is incorrect                               
ERROR class file version 61.0 is incorrect.Must be 52.0                                                             
ERROR Delete it or verify that it is in the correct subdirectory of the class path.

I don't know what the class file version refers to and what I have to do to compile it.
I deleted the import statement and I could compile it, so I think there might be a problem with the library version, but I'm not sure.
Could you tell me the cause and action?

java maven compiler

2022-09-30 19:49

1 Answers

"Class File Version" refers to which version of JVM was compiled.

The correspondence between the class file version and the Java version can be found in Specification .

The error message appears because your library genetics is being built for Java 17, but you are trying to build for Java 8 (typically using JDK8).

There are two options for dealing with this problem.

  • Using genetics for Java 8
    • v5.2.0 appears to be the final Java 8 compatible version
  • Build using JDK17 (or later)
  • v5.2.0 appears to be the final Java 8 compatible version

If you want to take the former action, you may want to rewrite the version number shown in the questionnaire.

<dependency>
        <groupId>io.genetics</groupId>
        <artifactId> genetics</artifactId>
        <version> 5.2.0</version>
    </dependency>

For the latter, set up JDK17 (or JDK18) and then target Java17 (or 18) with the maven-compiler-plugin option

.
<properties>
    <maven.compiler.source>17</maven.compiler.source>
    <maven.compiler.target>17</maven.compiler.target>
  </properties>


2022-09-30 19:49

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.