错误:java:javacTask:源版本 8 需要目标版本 1.8

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30431710/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 09:38:01  来源:igfitidea点击:

Error: java: javacTask: source release 8 requires target release 1.8

javamavenintellij-ideajava-8

提问by Dims

I have opened git project I was running under Eclipse previously in IntelliJ. I have changed to Java 8 in following places:

我已经在 IntelliJ 中打开了我之前在 Eclipse 下运行的 git 项目。我已在以下位置更改为 Java 8:

File -> Project Structure -> SDKs

and

File -> Project Structure -> Project

Where to set Java 8 else? What it wants?

在哪里设置Java 8?它想要什么?

The project is Maven, pom file has only dependenciessections

项目是Maven,pom文件只有dependencies部分

UPDATE

更新

I am trying to run under IntelliJ

我试图跑下 IntelliJ

回答by Krishanthy Mohanachandran

You can try this way:

你可以试试这个方法:

For Eclipse:

对于日食:

Windows -> Preferences -> Java -> Installed JREs -> add JDK

Windows -> Preferences -> Java -> Installed JREs -> add JDK

You can download the JDK for 1.8 and browse the file when you are trying to add JDK. If it's windows OS then you need to install Java 1.8 and then use the path from C:\Program Files\...\jdk1.8(Please refer this for reference)

您可以下载 JDK 1.8 并在尝试添加 JDK 时浏览该文件。如果是 Windows 操作系统,则需要安装 Java 1.8,然后使用来自的路径C:\Program Files\...\jdk1.8(请参阅此以供参考

The above is for setting eclipse.

以上是设置eclipse。

Then you need to apply changes for the project setup as below:

然后您需要对项目设置应用更改,如下所示:

Project -> Properties -> Java Build Path -> Libraries -> Click on JRE System Library -> Edit button -> change the Library as 8that you have set up for eclipse

Project -> Properties -> Java Build Path -> Libraries -> Click on JRE System Library -> Edit button -> change the Library as 8你为日食设置的

For IntelliJ, you can try this guide

对于 IntelliJ,你可以试试这个指南

回答by nesteant

In order to compile your code you should add maven build section:

为了编译你的代码,你应该添加 maven build 部分:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.2</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

Also you can go to File | Settings | Build, Execution, Deployment | Compiler | Java Compiler and change it there, but it will cause other developers failures as they need to modify IDE before build

你也可以去文件 | 设置 | 构建、执行、部署 | 编译器 | Java Compiler 并在那里更改它,但它会导致其他开发人员失败,因为他们需要在构建之前修改 IDE

回答by Tim Biegeleisen

In addition to what you have done, you also have to update the build Module.

除了你所做的,你还必须更新构建模块。

SHIFT + CTRL + ALT + S -> Modules -> Select JDK 1.8 and press apply

Check the output from your build to make sure that IntelliJ is using JDK 8 and not the earlier version (7?) which you had.

检查构建的输出以确保 IntelliJ 使用的是 JDK 8 而不是您拥有的早期版本 (7?)。