gpt4 book ai didi

java - 避免 Eclipse 中多个 Java 版本的 "no JREs installed in the workspace that are strictly compatible"警告

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:24:03 25 4
gpt4 key购买 nike

我知道已经有很多关于此警告的问题,但我的问题有点不同。我知道我可以在我的 pom.xml 中使用此配置修复它

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

这消除了警告,但前提是我在 Eclipse 中安装并配置了 Java 7。例如,如果我只有 Java 8,我仍然会看到警告,除非我将上面配置中的版本更改为 1.8:

Build path specifies execution environment JavaSE-1.7. There are no JREs installed in the workspace that are strictly compatible with this environment.

我的项目与 Java 7、8、9 和 10 兼容。我想要实现的是,如果安装了这些版本的 Java 中的任何一个而不更改我的 pom.xml 中的版本,则避免出现此警告。每次都匹配当前安装的 Java 版本。告诉 Eclipse Java 7 或更高版本的东西是好的。

该项目仍然可以编译并在警告的情况下正常工作,它只是分散注意力,因为它将项目标记为有问题。 我知道我可以在 Eclipse 设置中隐藏这种类型的警告,但是有没有办法通过使用 pom.xml 中的一些配置来摆脱它? ?

最佳答案

Eclipse 使用值 <target>1.7</target>决定将哪个执行环境包含在构建路径中,作为其 Maven 集成的一部分。

执行环境映射到安装在 Eclipse 中 的 JRE(即在 Preferences > Java > Installed JREs 中引用)。

映射本身在 Preferences > Java > Installed JREs > Runtime Environments 中配置. Eclipse 会自动将执行环境(例如 JavaSE-1.7 )与已安装的 JRE(例如 jdk1.7.0_80 )匹配。如果您的项目中指定的执行环境没有完全匹配,它会给您一个警告,就像您收到的警告一样。

因此,要消除警告,您必须:

  • 安装与您的 <target> 完全匹配的 Java 版本(即 jdk1.7 )并将其添加到 Preferences > Java > Installed JREs > Runtime Environments
  • 将您的 pom 中的 Java 版本配置为完全匹配的版本

My project is compatible with Java 7, 8, 9 and 10. What I want to achieve is to avoid this warning if any of these versions of Java is installed

配置执行环境使用时,Eclipse只关心<target>值(value)。您需要确保有一个 JRE 安装在 Eclipse 中,其版本与该属性的值完美匹配。否则,警告不会消失,期间。

I don't have the intention to target some specific version, the default target would work fine for me.

不,不会,因为默认目标是 1.5。目标配置是一个非可选的配置属性,没有“目标一切”选项。

您可以从构建路径中删除 Maven 配置的执行环境并直接添加 JRE ( project properties > Java Build Path > Libraries > Add library... > JRE System Library > Alternate JRE )。这也会使警告消失,但一旦您运行 Maven 项目更新,它就会恢复。这样的配置不应该真正使用,因为它会将您的项目与计算机上特定的 Java 安装联系起来。

关于java - 避免 Eclipse 中多个 Java 版本的 "no JREs installed in the workspace that are strictly compatible"警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50116802/

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