[idea]Error:java: invalid source release: 1.8

Open source software supply chain lighting plan, waiting for you>>>

There is a problem

Back to the point, the problem is that the default JDK version of my computer is 1.8.0_ 71. Then I usually use JDK version 1.7, which is installation free. I only configure environment variables. I usually don’t have this problem with eclipse development. Yesterday, idea didn’t have this problem either. As a result, I created a new project today, set JDK version and Tomcat to 1.7. After typing the code, I started it. This error is exploded, as follows:

E rror:java : invalid source release: 1.8

Problem solving

After checking some information, we have the following solutions:
1. Settings – > Build, Execution, Deployment -> Compiler -> Java compiler, and then set the project bytecode version to 1.7, as shown in the figure:

Here is the picture description

Tried, failed.

2.Project Structure -> Modules -> Dependencies, set the module SDK to 1.7, as shown in the figure below:

Here is the picture description

After checking, my setting is 1.7, failed

3. Finally, I found an article similar to my question

E rror:java : javacstask: source release 8 requires target release 1.8, so I went to check my language level, and it turned out to be 1.8, changed it to 7, and ran successfully!

Here is the picture description

Extracurricular extension

So what is the language level?I haven’t seen this concept in eclipse before. I checked it and explained it as follows:

When we use JDK 8, we can only downward compatible with JDK 8 and the following features, so we can only select language level 8 and the following. So when our project uses JDK 8, but the code does not use the new features of JDK 8, and uses the features of JDK 7 at most, we can choose 7 – diamonds, arm, multi catch, etc.

In this regard, we summarize language level: JDK features that limit the minimum requirements for project compilation checking.

Now suppose we have a new feature of JDK 8 used in the project code: lambda syntax, but JDK chooses JDK 7. Even if language level chooses 8 – Lambdas, type annotation, etc., it doesn’t make much sense. It will also compile and report errors.

So, language level is a bit like the minimum supported version of our project. For example, if the language level is set to 5.0, the 6.0/7.0 feature code will not appear.

This article shares CSDN – Donghai Chen Guangjian.

Similar Posts: