且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

更新Maven不断从Java JDK 1.8恢复到Eclipse中的JavaSE -1.8

更新时间:2021-11-23 00:43:35

您需要了解什么是执行环境(EE )是在Eclipse中. EE的概念是对JRE的抽象,允许在配置项目时没有指向JRE位置的绝对路径.在Wiki页面上:

You need to understand what an Execution Environment (EE) is in Eclipse. The concept of EE is an abstraction over JREs, allowing projects to be configured without absolute paths to JRE locations. From the wiki page:

执行环境(EE)是JRE的符号表示.例如,您可以谈论J2SE-1.4执行环境,而不是谈论在磁盘上特定位置使用特定名称的特定JRE.然后可以将系统配置为使用特定的JRE来实现该执行环境.

Execution environments (EEs) are symbolic representations of JREs. For example, rather than talking about a specific JRE, with a specific name at a specific location on your disk, you can talk about the J2SE-1.4 execution environment. The system can then be configured to use a specific JRE to implement that execution environment.

通常,建议不要将项目配置为使用默认工作区"作为其JRE系统库,因为这会使项目在加载到不同的工作区时不一致.考虑一下:如果该项目是针对Java 7开发的,但是我将其放入具有JDK 8的工作区中,该怎么办?那可能是个大问题.通过使用EE,可以对项目进行配置,以使其不知道(或不关心)我的系统上实际有匹配的JRE的位置.

In general, it's not advisable to configure a project to use "Workspace default" as its JRE System Library, because that makes the project inconsistent when loaded into different workspaces. Think about this: what if the project is being developed targeting Java 7, but I pull it into my workspace which has JDK 8; that could be a big problem. By using an EE, the project is configured such that it doesn't know (or care) where I actually have a matching JRE on my system.

我说了所有这些都是为了为您设置答案,因此您了解了Maven在做什么以及这些说明正在做什么. m2e是Eclipse的Maven集成插件,正在(正确地)将项目配置设置为使用EE而不是默认工作区".从屏幕截图中,我可以看到您在工作空间中同时设置了JDK和JRE 1.8,因此理想情况下,您应该删除其中一个(即JRE).转到首选项> Java > 已安装的JRE .在那里,您将看到列出的JRE和JDK.我建议删除JRE *.

I said all that to set up the answer for you, so you understand what Maven is doing and these instructions are doing. m2e, the Maven integration plugin for Eclipse, is (rightly) setting the project configuration to use an EE instead of "workspace default". From your screen shot I can see that you have both JDK and JRE 1.8 set up in your workspace, so ideally you should remove one (the JRE). Got to Preferences > Java > Installed JREs. There you'll see both the JRE and JDK listed. I suggest removing the JRE*.

然后进入执行环境"首选项部分,选择 JavaSE-1.8 并确保已将JDK选中为默认实现.

Then go into the "Execution Environments" preferences section, select JavaSE-1.8 and make sure that your JDK is checked as the default implementation.

现在,当m2e将您的项目配置为使用EE时,该EE将指向您已安装的JDK.而且,如果其他人导入了该项目,它将指向他们安装了匹配的JDK的任何地方.

Now when m2e configures your projects to use an EE, that EE will be pointing to the JDK you have installed. And if someone else imports the project, it will point to wherever they have a matching JDK installed.

*顺便说一句,在那里有不同版本的Java是完全可以接受和正常的;我经常从事针对不同Java版本的不同项目.

*By the way, it's perfectly acceptable and normal to have different versions of Java there; I often work on different projects that target different Java versions.