Solution for JAVA 'Invalid Target Release 17'

Niu Ma's daily regain of SpringMVC's "invalid target distribution"

Question: screenshot of death

insert image description here

Problem solving idea: This is an error caused by a mismatch of JDK versions.

Let me first talk about the key to the problem, and then elaborate on the solution steps:

Friends who encounter this problem are most likely to encounter it when writing Spring projects, which requires Maven to manage the project, and whether the jdk version of Maven matches is the root cause of this problem.

The root of this problem is whether the JDK used by your existing project is the same as the JDK version when maven is built.

Organized a solution:

  1. The first thing programmers think of is the operation of modifying the jdk version in Setting.

insert image description here
It is true that the jdk selection of the project can be changed in the Setting.
insert image description here
Generally, the problem cannot be solved after this operation.

  1. Modify the project configuration in Structure

insert image description here
Both Source and Dependencies need to be modified to the jdk version required by the project
insert image description here

insert image description here
Again, this operation still does not solve the problem. Still getting the same error when running the project??.

  1. Here you need the last step of operation, go to Setting to find the path of Maven's set.xml file

insert image description here
Delete the original JDK configuration (version 17), add the target jdk version, and provide version 1.8 configuration information here.

        <profile>
            <id>jdk-1.8</id>
            <activation>
                <activeByDefault>true</activeByDefault>
                <jdk>1.8</jdk>
            </activation>
            <properties>
                <maven.compiler.source>1.8</maven.compiler.source>
                <maven.compiler.target>1.8</maven.compiler.target>
                <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
            </properties>
        </profile>

In the end, it's the K of O.

Guess you like

Origin blog.csdn.net/m0_67391121/article/details/126020133