gpt4 book ai didi

java - 关于 intellij 中 Jdk5 的错误,即使 pom.xml 明确地将源设置为 7

转载 作者:搜寻专家 更新时间:2023-11-01 02:40:36 24 4
gpt4 key购买 nike

我在 Intellij (14.1.4 Ultimate) 中打开了一个 maven 项目,但 JDK 未被识别。当尝试运行其中一个程序时,会发生以下错误 - 在任何情况下,在 IDE 中查看时,文件中都会有一堆“红色”:

Error:(55, 50) java: diamond operator is not supported in -source 1.5
(use -source 7 or higher to enable diamond operator)

这很奇怪,因为使用 java7 的正常设置已经到位:

pom.xml 中:

        <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>

在项目中——JDK级别设置为7:

enter image description here

同样在模块中:

enter image description here

但是我们在尝试编译时遇到了各种各样的问题(即使在重新导入 maven 项目之后):

enter image description here

注意:这个项目确实使用 maven 在命令行上构建/运行。

另请注意:我已经尝试过取消 Intellij 项目并从头开始重建。行为没有变化。

更新 以下是@Peter Lawrey 的以下(已接受)回答的结果。我们可以看到 jdk 神秘地设置为 1.5。我已手动将其更新为 1.7。

enter image description here

最佳答案

有时 IntelliJ 会感到困惑,但我不知道为什么。你需要的设置是

File -> Settings -> Build, Execution, Deployment -> Compiler -> Java Compiler

找到您的模块并将其更改为版本 1.7 而不是 1.5。

我的项目有很多模块和相同的父 pom,它设置了这个,有时只有许多模块中的一个会认为它是 1.5,而其余的是 1.8。即跨多个模块的相同配置。

关于java - 关于 intellij 中 Jdk5 的错误,即使 pom.xml 明确地将源设置为 7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34272652/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com